Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dompdf inserts blank page at end of document

Tags:

php

dompdf

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.

like image 417
atonyc Avatar asked Jan 10 '14 07:01

atonyc


1 Answers

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.

like image 155
atonyc Avatar answered Oct 04 '22 22:10

atonyc