E
E
Exterrium2016-06-08 14:02:03
PHP
Exterrium, 2016-06-08 14:02:03

Blank screen when using dompdf: who faced?

I'm trying to generate a PDF from HTML using dompdf, but when I run the script, I see a blank page in the browser. Error output is enabled, but nothing is output.
Here is the code itself (using the example from the readme):

require_once '/var/www/tools/dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$dompdf->stream();

Tried that - to no avail. The browser has an empty page, the file is not created on the server.
$dompdf->stream('/var/www/hello.pdf');
I added this line, but there were no visible changes:
$dompdf->set_option('isHtml5ParserEnabled', true);
In general, I don’t see a single clue. I would be very grateful for any advice!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2016-06-08
@webinar

Here are the docs https://github.com/dompdf/dompdf/wiki/Usage it clearly states:
The question arises: "What do you have in $_dompdf_warnings?"
And also what do you have in $dompdf->output ?

A
auzil, 2016-10-21
@auzil

We need logos.
A white screen is normal, but you are streaming the file to the browser.
of course it didn’t help - if you take a minute and look into this very dompdf, you can find out what the stream function does

/**
     * output the pdf code, streaming it to the browser
     * the relevant headers are set so that hopefully the browser will recognise it
     */
    function stream($options = '')

if you need to save the file on the server, then you need to call after rendering:
/**
     * Returns the PDF as a string
     *
     * The file will open a download dialog by default.  The options
     * parameter controls the output.  Accepted options are:
     *
     *
     * 'compress' = > 1 or 0 - apply content stream compression, this is
     *    on (1) by default
     *
     *
     * @param array $options options (see above)
     *
     * @return string
     */
    public function output($options = null)

and then save this case on the server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question