phpwkhtmltopdf: Hangs indefinitely when exporting a password protected page (using --cookie)

I’m currently facing an issue where, if I add --cookie as an argument and pass in a sessionid, the request hangs indefinitely. However, when remove the --cookie, it works just fine but then the page exported to PDF becomes the login page of the site. I’m unable to export pages that requires some sort of authentication.

Here’s a snippet example:

$options = [
    'binary' => 'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf',
    'commandOptions' => [
        'useExec'     => true,
        'escapeArgs'  => false,
        'procOptions' => array(
            // This will bypass the cmd.exe which seems to be recommended on Windows
            'bypass_shell'    => true,
            'suppress_errors' => false
        )
    ],
];
$pdf = new Pdf($options);
$pdf->addPage($link_to_html);
$pdf->send();

Is this a known issue? Are you aware of any potential causes of this issue?

Thanks in advance

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (10 by maintainers)

Most upvoted comments

When you create a PDF from a Yii 1.1 request with a session and the page to be converted also accesses this session (by passing the session ID as cookie), then 2 requests need to be processed at the same time. and yii 1.1 is not capable of that. It waits, until the first process has finished and would then complete the second one (the one from wkhtmltopdf). And this never happens 😃

Solution: Before calling wkhtmltopdf close the session manually by calling session_write_close() before (in which ever way) calling wkhtmltopdf. cheerio