dongshuo5101 2013-01-16 05:11
浏览 117
已采纳

不打印FPDF A4尺寸

I use FPDF for PDF generation in my project. I want to generate A4 size page and I use following line.

$fpdf = new PDF('P','mm',array(595.28,841.89));
$fpdf->AddPage('P', 'A4'); 

I generate the PDF using this code and I got print out. Then I realize that the page size is not fit for the A4.
Can somebody help me on this regard?

  • 写回答

1条回答 默认 最新

  • dongque1462 2013-01-16 05:49
    关注

    The problem is that you pass the wrong default page size (595.28mm by 841.89mm) to the FPDF constructor, which by the way should be FDPF. A4 is 210mm by 297mm if in portrait mode.

    So you should call the constructor this way:

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

    or

    $pdf = new FPDF('P','mm',array(210,297));
    

    After that you can omit the page size parameter when calling AddPage().

    Here is a complete Hello World example:

    <?php
    require('fpdf.php');
    
    $pdf = new FPDF('P','mm','A4');
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->Cell(40,10,'Hello World!');
    $pdf->Output();
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器