简体   繁体   中英

Print dompdf table issue

Print dompdf table issue: DomPDF table goes out of pdf while printing. Can anyone help me in this. I am in need to break the table width according to content.

This is one of the problems with DOMPDF, and there is no work-around, except for you controlling how much content can be on a page, and creatively using CSS to break your content up so that it doesn't overlap pages. You must break your tables into more than one table, then tell DOMPDF where your page breaks are.

In my own DOMPDF usage, I include CSS styles at the top of the HTML. Notice the CSS "page-break-before" property:

<!doctype html>
<html>
<head>
    <title>Dynamically Generated PDF</title>
    <style>
        #page_break{
            page-break-before:always;
        }
    </style>
</head>
<body>
    <!-- Contents of PDF -->
</body>
</html>

There is another CSS property you can use to break up page, "page-break-after".

You use this CSS and apply it to elements where you know you want a page break, for instance:

<h2 id="page_break">Table 1:</h2>
<table>
    <!-- table content -->
</table>

<h2 id="page_break">Table 1 (continued):</h2>
<table>
    <!-- table content -->
</table>

This breaks the content into pages, and in this case this H2 tags would be at the top of the pages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM