1

I have installed the wonderful software wkhtmltopdf on our production Debian server to be used for creating PDFs from URLs. We stream (i hope that's the right term) the resulting PDF to the client, we have no interest in storing them server side.

We only generate PDFs from local URLs (on the own server that is). However, the URL is still based on the domain and not the local IP since there are multiple sites on the server.

Our problem is that for some local pages, all we get back is a entirely blank page (not even a PDF). The response code is 200, but the content-type is text/html. For those pages where a PDF is successfully streamed to the client, the content-type is application/pdf.

I thought that maybe something goes wrong in the generation of my PDF, so i ran exactly the same commands that PHP executes, and then a PDF was being generated successfully.

I am using the library found on this page to make PHP connect with wkhtmltopdf.

$pdf = new WkHtmlToPdf(array(
        'margin-left'=>0,
        'margin-right'=>0,
        'margin-top'=>0,
        'margin-bottom'=>0,
        'print-media-type',
        'disable-smart-shrinking'
    ));
    $url = "http://myserver.se/$url";
    $pdf->addPage($url);
    $pdf->send();

Why do i get blank pages back for some URLs?

Anton Gildebrand
  • 3,641
  • 12
  • 50
  • 86

1 Answers1

0

It turned out, the problem was in the library i was using. I can't tell exactly what the problem was, but proc_close in the send method of the wkhtmlpdf class was returning 2 instead of the expected 0 when a PDF was succesfuly created. This lead to that the library thought that no PDF was created, and it simply returned false meaning nothing was outputted to the client. I solved it by checking if the file existed instead by using PHP's file_exists function.

Anton Gildebrand
  • 3,641
  • 12
  • 50
  • 86