doujia9833 2015-07-10 07:26
浏览 50

laravel dom的页码pdf

I'm using laravel framework in php.

I have Generated the plugin by using this barryvdh/laravel-dompdf

And now my question is how to create the page number for seprate page in pdf like page 1 and page 2 like this in barryvdh/laravel-dompdf ?

<?php
require_once("dompdf_config.inc.php");

$html =
  '<html><body>'.
  '<p>Put your html here, or generate it with your favourite '.
  'templating system.</p>'.
  '</body></html>';

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");

?>
  • 写回答

1条回答 默认 最新

  • doumeng4400 2015-07-20 17:53
    关注

    For the page count you can use CSS counters.

    <html>
    <head>
      <style>
      .page-num:before { content: counter(page); }
      </style>
    </head>
    <body>
      <p>Page <span class="page-num"></span></p>
    </body>
    </html>
    

    Unfortunately dompdf does not yet support the total number of pages using counters (for text similar to "page 1 of 3"). For that you would have to use script.

    <?php
    require_once("dompdf_config.inc.php");
    
    $html = '...';
    
    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->render();
    
    $pdf = $dompdf->get_canvas()->get_cpdf();
    $x = 10; // from left
    $y = 10; // from bottom
    $text = "Page {PAGE_NUM} of {PAGE_NUM}"; // {PAGE_NUM} and {PAGE_COUNT} are placeholders populated by dompdf
    $font = Font_Metrics::get_font("arial", "normal");
    $size = "10"; // in pt
    $color = array(.3, .3, .3); // rgb, valid values are between 0 and 1
    $pdf->page_text($x, $y, $text, $font, $size);
    
    $dompdf->stream("sample.pdf");
    ?>
    

    Note: the above script snippet is specific to v0.6.x using the CPDF backend.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答