Skip to content
Advertisement

dompdf inserts blank page at end of document

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.

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement