2017-01-05 52 views
1

我創建了一個從數據庫mysql中獲取數據的dompdf。但我的問題是我如何迭代一個頁面,如果每個用戶的數據將超過19個交易?如何在dompdf中創建多個頁面

<?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樣本輸出是這樣的:

Outout

這裏任何人能幫助我嗎?

感謝。

+0

dompdf自動進行分頁。如果你想強制分頁,你可以通過CSS /使用'page-break-before:always;'或'page-break-after:always;'來設置一個元素。希望這可以幫助你 –

+0

@PunitGajjar,但它看起來不像我添加的圖像,我猜。請檢查我添加了一個輸出。 – rolex

+0

您正在給內聯CSS添加元素嗎? ? –

回答

0

試試這個

$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); 

在代碼中實現此代碼。