php中怎么写分页符,php fpdf分页符

我正在使用php和fpdf生成包含项目列表的pdf。我有一个循环,在这个循环中,我用gety()进行了一个验证,以检查什么时候会中断。这工作很好,但在第一页,不。这是创建网页,但在第一页,没有打破文本到第二页像其他人一样。我该怎么办?

[...]

if ($pdf->GetY() > 230) {

$pdf->AddPage();

}

endwhile;

完整代码:

if($_GET['print'] == 'ok'){

$idO = $_GET['id'];

require_once "assets/fpdf/fpdf.php";

$pdf = new FPDF( 'P', 'mm', 'A4' );

$pdf->AddPage();

$pdf->SetFillColor( 255, 255, 255 );

$pdf->SetDrawColor( 255, 255, 255 );

$pdf->AliasNbPages();

$pdf->SetAutoPageBreak(true, 30);

$itens = get_field('itens', $idO);

$args = array(

'post_type' => 'categorias',

'posts_per_page' => -1,

'meta_key' => 'ordem',

'orderby' => 'meta_value',

'order' => 'ASC',

'meta_query' => array(

'key' => 'status',

'value' => 'ativo',

'compare' => '='

)

);

$query = new WP_Query($args);

$i=0;

while ($query->have_posts()):$query->the_post();

foreach ($itens as $key => $value){

if(get_field('categoria', $value) == get_the_ID()){

$i++;

$pdf->SetFont( 'Arial', 'B', 10 );

if($i == 1){

$pdf->MultiCell( 0, 10, utf8_decode(html_entity_decode(get_the_title($value))).':', 0, 'C', false );

$imgWidth = 65;

$f = get_field('principal', $value);

$wI = get_field('_wp_attachment_metadata', get_field('foto'.$f, $value))['width'];

$hI = get_field('_wp_attachment_metadata', get_field('foto'.$f, $value))['height'];

$pY = ($imgWidth * $hI) / $wI;

$pX = ($pdf->GetPageWidth() - $imgWidth) / 2;

$img = wp_get_attachment_image_src( get_field('foto'.$f, $value), 'full' )[0];

$pdf->Image($img,$pX,$pdf->GetY(),$imgWidth);

$pdf->Ln( $pY );

$pdf->MultiCell( 0, 5, "Gabinete:", 0, 'L', false );

} else{

$pdf->MultiCell( 0, 5, utf8_decode(html_entity_decode(get_the_title($value))).':', 0, 'L', false );

}

if(get_field('modelo', $value) != ''){

$pdf->Ln(2);

$pdf->SetX(20);

$pdf->SetFont( 'Arial', 'B', 10 );

$pdf->MultiCell( 0, 5, "Modelo: ", 0, 'L', false );

$pdf->SetX(25);

$pdf->SetFont( 'Arial', '', 10 );

$pdf->MultiCell( 0, 5, utf8_decode(get_field('modelo', $value)), 0, 'L', false );

}

if(get_field('fabricante', $value) != ''){

$pdf->Ln(2);

$pdf->SetFont( 'Arial', 'B', 10 );

$pdf->SetX(20);

$pdf->MultiCell( 0, 5, "Fabricante: ", 0, 'L', false );

$pdf->SetX(25);

$pdf->SetFont( 'Arial', '', 10 );

$pdf->MultiCell( 0, 5, utf8_decode(get_field('fabricante', $value)), 0, 'L', false );

}

$pdf->SetX(20);

$pdf->SetFont( 'Arial', 'B', 10 );

$pdf->MultiCell( 0, 10, utf8_decode("Especificações Técnicas:"), 0, 'L', false );

$pdf->SetX(25);

$pdf->SetFont( 'Arial', '', 10 );

$pdf->MultiCell( 0, 5, utf8_decode(html_entity_decode(get_field('descricao', $value))), 0, 'L', false );

if($i > 1){

if(get_field('exibir', $value) != ''){

$pdf->Ln( 2 );

$x=0;

foreach (get_field('exibir', $value) as $key2 => $value2){

$x++;

$imgWidth2 = 20;

$wtP = ($imgWidth2 * $x);

$pX2 = ($x == 1)?($pdf->GetX() + $wtP):($pdf->GetX() + $wtP + 5);

$img2 = wp_get_attachment_image_src( get_field('foto'.$value2, $value), 'full' )[0];

$pdf->Image($img2,$pX2,$pdf->GetY(),$imgWidth2);

}

$pdf->Ln( 25 );

}

}

if ($pdf->GetY() > 265) {

$pdf->AddPage();

}

}

$pdf->Ln( 2 );

}

endwhile;

wp_reset_query();

$pdf->Output('', 'relatorio.pdf');

die();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值