【问题标题】:How to create multiple page in dompdf如何在dompdf中创建多个页面
【发布时间】:2017-05-19 12:40:18
【问题描述】:

我创建了一个 dompdf,它从数据库 mysql 中获取数据。但我的问题是,如果每个用户的数据将超过 19 个事务,我将如何迭代页面?

<?php
define( 'WP_USE_THEMES', false );
define( 'COOKIE_DOMAIN', false );
define( 'DISABLE_WP_CRON', true );
require('wp-load.php'); 

global $current_user;
get_currentuserinfo();

$d = $current_user->user_login;

// include autoloader
require_once 'dompdf/autoload.inc.php';

// reference the Dompdf namespace
use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();

$html = '<html><body>'.
        '<p>Date | Details </p>';

$ff = $wpdb->get_results( "SELECT * FROM table WHERE dd = '$d' ORDER by tdate");
    foreach ( $ff as $jj ) {
     $html = '<p>'.$jj->tdate.' | '.$jj->details.'</p>';
    }

$html .= ''</body></html>';

$dompdf->loadHtml($html);

// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
//$dompdf->stream();

// Output the generated PDF (1 = download and 0 = preview)
$dompdf->stream("codex",array("Attachment"=>0));

目前它仅适用于 1 页,但我的问题是当每个用户的数据超过 19 到更高的事务时,它会破坏页面。我想设置每页 19 笔交易。

BTW 示例输出如下所示:

这里有人可以帮帮我吗?

谢谢。

【问题讨论】:

  • dompdf 自动进行分页。如果你想强制分页,你可以通过 CSS/样式化元素来做到这一点page-break-before: always;page-break-after: always;。希望对你有帮助
  • @PunitGajjar 但我猜它看起来不像我添加的图像。请检查我添加了一个输出。
  • 你给元素提供内联 CSS 对吗? ?
  • @PunitGajjar 不,我刚刚添加了一个外部 CSS。
  • 试试内联 CSS 好友...

标签: php mysql dompdf


【解决方案1】:

试试这个

$start = '<html><body>';
$body  = '<p>Date | Details </p>';
$ff = $wpdb->get_results( "SELECT * FROM table WHERE dd = '$d' ORDER by tdate");
    foreach ( $ff as $jj ) {
     $body .= '<p>'.$jj->tdate.' | '.$jj->details.'</p>';
    }
$end= '</body></html>';
$dompdf->loadHtml($start.$body.$body.$end);

在您的代码中实现此代码。

【讨论】:

    猜你喜欢
    • 2012-12-14
    • 2017-11-17
    • 1970-01-01
    • 2014-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-02
    相关资源
    最近更新 更多