HTML2Pdf内容溢出页面

时间:2015-11-27 14:04:00

标签: php html css html2pdf

我正在尝试使用HTML2PDF库从HTML文件生成PDF。

我的HTML:

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
    <td align="center" valign="top">
        <table width="968" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td align="center" valign="top">
                    <strong>Invoice </strong>
                </td>
            </tr>
            <tr>
                <td align="right" valign="top">
                    <span style="text-align:right;">#24638 </span>
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    <table width="968" border="0" align="center" cellpadding="0" cellspacing="0">
                        <tr>
                            <td width="50%" align="left" valign="top">
                                <table width="500" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td align="left" valign="top">To</td>
                                    </tr>
                                    <tr>
                                        <td align="left" valign="top">test user
                                            <br />
                                             Some Company22
                                            <br />
                                            My Address
                                            <br />
                                             Line 2
                                            <br />
                                            City, 487030
                                            <br />
                                            State, Country
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td width="50%" align="left" valign="top">&nbsp;</td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">&nbsp;</td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    <table width="968" border="1" cellspacing="1" cellpadding="1">
                        <tr>
                            <td width="17%" align="center" valign="top">Transaction Date</td>
                            <td width="6%" align="center" valign="top">User ID</td>
                            <td width="26%" align="center" valign="top">UserName</td>
                            <td width="9%" align="center" valign="top">Order</td>
                            <td width="21%" align="center" valign="top">Tax </td>
                            <td width="21%" align="center" valign="top">Tax Description</td>
                        </tr>
                        <tr>
                            <td align="center" valign="top">04-11-2015</td>
                            <td align="center" valign="top">137</td>
                            <td align="center" valign="top">saurabh.pande@dfordomains.com</td>
                            <td align="center" valign="top">24727</td>
                            <td align="center" valign="top">Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</td>
                            <td align="center" valign="top">Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Mauris placerat </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">&nbsp;</td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    <table width="968" border="1" align="left" cellpadding="1" cellspacing="1">
                        <tr>
                            <td width="49%" align="center" valign="top">Description</td>
                            <td width="27%" align="center" valign="top">Invoice Amount</td>
                            <td width="24%" align="center" valign="top">Pending Amount</td>
                        </tr>
                        <tr>
                            <td align="center" valign="top">Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo</td>
                            <td align="center" valign="top">USD 5.98 </td>
                            <td align="center" valign="top">USD 0 </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">&nbsp;</td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    <table width="500" border="1" cellspacing="1" cellpadding="1">
                        <tr>
                            <td width="51%" align="left" valign="top">Foreign Exchange Rate when Invoice was paid (EUR To USD) </td>
                            <td width="49%" align="left" valign="top">Mauris placerat </td>
                        </tr>
                        <tr>
                            <td align="left" valign="top">Total Amount</td>
                            <td align="left" valign="top">USD 5.98</td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">&nbsp;</td>
            </tr>
            <tr>
                <td align="left" valign="top">&nbsp;</td>
            </tr>
        </table>
    </td>
</tr>

我使用此代码来生成PDF:

$pdfdata = myHtml() // returns my generated HTML
require_once(__DIR__.'path/to/html2pdf/html2pdf.class.php');
try{
    $html2pdf = new HTML2PDF('P','A4','en');
    $html2pdf->WriteHTML($pdfdata);
    $html2pdf->Output('transaction.pdf');
}catch(Exception $e){
    echo $e->getMessage();
}

但是在输出中,表格宽度超出了页面宽度,一半的内容不可见。enter image description here

1 个答案:

答案 0 :(得分:-1)

you can use the <page> it is bordered to your pdf pages

<page backtop="30mm" backbottom="15mm" backleft="5mm" backright="10mm" pagegroup="new" style="font-family: freeserif;">     
    <page_header>                 
    </page_header>
    <page_footer style="text-align: center;">
    </page_footer>
</page>