首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >dompdf在中生成PDF,内容之间有许多空白页面

dompdf在中生成PDF,内容之间有许多空白页面
EN

Stack Overflow用户
提问于 2013-12-11 20:18:35
回答 2查看 7.6K关注 0票数 0

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

代码语言:javascript
运行
复制
<?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文件

代码语言:javascript
运行
复制
http://jsfiddle.net/6RmmB/

因为生成了PDF,所以我不认为PHP代码有任何问题。一定是html中出了什么问题,但又不能弄清楚到底是什么?

或者我在PHP代码中遗漏了什么?

“雇主识别号码”旁边的内容出现在大约8-9个空白页之后

EN

回答 2

Stack Overflow用户

发布于 2013-12-17 23:36:00

这似乎是由于dompdf处理paging of table cells的方式中的一个错误。如果删除外层表格,则页面的呈现效果会更好。然而,您可能仍然需要调整结构/样式,以获得您想要的内容。

例如,而不是这样:

代码语言:javascript
运行
复制
<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>

执行以下操作:

代码语言:javascript
运行
复制
<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>
票数 3
EN

Stack Overflow用户

发布于 2018-03-01 04:23:52

当多个表不适合一页时,我会遇到问题。这个问题的解决方案很简单,在表后添加<div style="clear: both;">

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20518964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档