2013-12-11 121 views
0

我正在使用DOMPDF从html生成pdf文件。 PDF文件正在生成,但内容之间出现许多空白页面。以下是我的PHP代码。dompdf在内容之间生成许多空白页面的PDF

<?php 
    $html=file_get_contents("views/testnew.html"); 
// echo $html;die(); 
    $paper_orientation = 'landscape'; 

    ob_start(); 
    require_once("dompdf/dompdf_config.inc.php"); 
    $pdfcontent = $html; 

    $dompdf = new DOMPDF(); 
    $dompdf->set_paper('A4', $paper_orientation); 
    $dompdf->load_html($pdfcontent); 
    $dompdf->render(); 

// $pdf = $dompdf->output(); 
    $pdf=$dompdf->stream("my_pdf.pdf", array("Attachment" => 0)); 
// file_put_contents('Brochure.pdf', $pdf); 
?> 

以下是我的HTML这是我在PDF文件

http://jsfiddle.net/6RmmB/ 

由于PDF是如何产生,我不认为这是用PHP代码的任何问题写。 html中的某些东西一定是错的,但是无法弄清楚究竟是什么?

或者我错过了PHP代码中的东西?

内容旁边的“雇主识别号码”后,由于DOMPDF如何处理paging of table cells错误约8-9空白页

回答

2

这看起来是出现。如果您移除似乎只存在以提供边框的外部表格,则该页面的渲染效果会更好。你可能仍然需要调整结构/样式,但是,要得到你想要的。

例如,而不是这样的:

<table width="100%" border="0" cellpadding="0" cellspacing="0" id="" style="border:1px solid #ccc;color: #000;font-family: Arial,Helvetica,sans-serif;font-size:14px;"> 
    <tr> 
     <td> 
      <table width="100%" cellspacing="0" cellpadding="0" border="0" style="border-bottom:1px solid #ccc"> 
       <tr> 
        <td width="15%" align="left" valign="top" style="border-right:1px solid #ccc;padding:10px;line-height:20px">Form 
         <img src="/var/www/html/pm5/bodytechniques/working/development/version5/therapist/images/w9-form.JPG" width="83" height="37" style="margin-left:15px" /> 
         <br>(Rev. August 2013) 
         <br>Department of the Treasury 
         <br>Internal Revenue Service</td> 
        <td width="69%" align="left" valign="top" style="border-right:1px solid #ccc;padding:10px;text-align:center;line-height:45px"> 
         <h1 align="center">Request for Taxpayer Identification Number and Certification</h1> 
        </td> 
        <td width="16%" align="left" valign="top"> 
         <h3 style="line-height:25px;padding:10px">Give Form to the requester. Do not send to the IRS</h3> 
        </td> 
       </tr> 
      </table> 
     </td> 
    </tr> 
</table> 

这样做:

<div style="border:1px solid #ccc;color: #000;font-family: Arial,Helvetica,sans-serif;font-size:14px;"> 
    <table width="100%" cellspacing="0" cellpadding="0" border="0" style="border-bottom:1px solid #ccc"> 
     <tr> 
      <td width="15%" align="left" valign="top" style="border-right:1px solid #ccc;padding:10px;line-height:20px">Form 
       <img src="/var/www/html/pm5/bodytechniques/working/development/version5/therapist/images/w9-form.JPG" width="83" height="37" style="margin-left:15px" /> 
       <br>(Rev. August 2013) 
       <br>Department of the Treasury 
       <br>Internal Revenue Service</td> 
      <td width="69%" align="left" valign="top" style="border-right:1px solid #ccc;padding:10px;text-align:center;line-height:45px"> 
       <h1 align="center">Request for Taxpayer Identification Number and Certification</h1> 
      </td> 
      <td width="16%" align="left" valign="top"> 
       <h3 style="line-height:25px;padding:10px">Give Form to the requester. Do not send to the IRS</h3> 
      </td> 
     </tr> 
    </table> 
</div> 

下面是完整的文档小提琴:对于下载PDF http://jsfiddle.net/bsweeney/6RmmB/2/

1

我使用DOMPDF hml页面。下载许多空白页面时,内容之间会出现。我使用表格作为内容。请帮助任何人解决此问题。这里是我的代码

$dompdf = new DOMPDF(); 
     //$dompdf->load_html(file_get_contents($filename)); 
     $dompdf->load_html($data); 
     $dompdf->set_paper("letter", "portrait"); 
     $dompdf->render(); 

     //$dompdf->stream($filename. ".pdf", array("Attachment" => 0)); 
     $output = $dompdf->output(); 
0

我有问题,当多个表不适合一个页面。 解决方案很简单,在表格后添加<div style="clear: both;">