dompdf inserts blank page at end of document

atonyc

I'm generating a pdf document using dompdf 0.6.0, and have a strange issue where a blank page is being created at the end. My (simplified) html:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>PDF</title>
<style type="text/css">
@page{ margin: 0;}

.page{
    width: 612px; 
    height: 792px; 
    overflow: hidden; 
    font-family: Arial, Helvetica; 
    position: relative; 
    color: #545554;
    page-break-after: always;
}
</style>
</head>
<body>
<div class="page" style="background-image: url(page1.jpg);">
...
</div>

<div class="page" style="background-image: url(page2.jpg);"></div>

<div class="page" style="background-image: url(page3.jpg); color: white;">
...
</div>
</body>
</html>

The first three pages look amazing, but there is a blank page at the end. I've read dompdf is picky about nesting and compliance and such, but the html is super clean and checks out.

atonyc

Turns out the end </body> and </html> tags were causing the extra page. I removed them, and results are as expected.

I'd imagine its a problem with dompdf, but I spent quite awhile trying to solve the issue and figured this might be of help to others.

Update:

As Joe mentions in the comments, moving the </body> and </html> tags to the same line as your closing </div> works, and remains valid html.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Dompdf default page header content overlap

From Dev

Adding cover image with page number in dompdf

From Dev

Blank page on startup

From Dev

Printf inserts % at the end of the line

From Dev

Copy document by page to insert blank page in between using iTextsharp

From Dev

Blank Page with PHP script

From Dev

Render a Blank Page with Ghostscript

From Dev

printdocument adds blank page

From Dev

DOMPDF - break page when not fit content

From Dev

Chrome print blank page

From Dev

dompdf page_script() variables

From Dev

dompdf timeout when printing 25 page pdf

From Dev

Blank page with Polymer

From Dev

DomPDF {PAGE_NUM} not on first page

From Dev

WooCommerce category page is blank

From Dev

Make an image in dompdf cover all of the first page

From Dev

dompdf - set page margin only after first page

From Dev

DOMPDF page orientation both landscape and portrait

From Dev

How to make "document.write" in an if statement work on the same html page rather than a new blank page?

From Dev

dompdf freezes not showing content. page is blank

From Dev

Print range - print from page x until end of document

From Dev

dompdf, Store the Contents of a Wordpress Page in a Variable

From Dev

Unwanted blank space generated at the end of page

From Dev

How to render DOMPDF within a page

From Dev

Laravel 5 domPDF PAGE_NUM and PAGE_COUNT

From Dev

dompdf timeout when printing 25 page pdf

From Dev

how to get page count in dompdf without using page text

From Dev

Loop to add blank lines that repeats until end of the Word document

From Dev

document.write blank page