Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Blank pages when returning buffer of generated PDF #82

Open
niamzor opened this issue Feb 28, 2020 · 5 comments
Open

Blank pages when returning buffer of generated PDF #82

niamzor opened this issue Feb 28, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@niamzor
Copy link

niamzor commented Feb 28, 2020

I'm trying to generate a PDF from an url and return this pdf without saving it to the server filesystem.

$puppeteer = new Puppeteer();
$browser = $puppeteer->launch([
    "ignoreHTTPSErrors"     => true,
    "args"                  => ['--no-sandbox', '--disable-setuid-sandbox']
]);
$page = $browser->newPage();
$page->goto($url, ["waitUntil" => "networkidle0"]);
$buffer = $page->pdf([
    "path"                  => $filepath,
    "format"                => "A4"
);
$browser->close();

return new Response(
    $buffer->toString(),
    201,
    [
        'Content-Type'          => 'application/pdf',
        'Content-Disposition'   => 'inline; filename="file.pdf"'
    ]
);

For testing purposes, I use the path option to actually generate a PDF on the filesystem. This generated PDF is absolutely fine whereas the one returned by Symfony in the client browser is blank, though the number of pages is alright.

I had tried to return a BinaryFileRespones or a StreamedResponse with no luck.

Any hints appreciated
puphpeteer.log

@niamzor niamzor changed the title Nothing is displayed when returning buffer of generated PDF Blank pages when returning buffer of generated PDF Feb 28, 2020
@jonnywilliamson
Copy link

I'm getting exactly the same thing. Thanks for letting me know that the data written to disk works!!

@nesk
Copy link
Member

nesk commented Sep 21, 2020

Related to #87

@nesk nesk added the bug Something isn't working label Sep 21, 2020
@spekulatius
Copy link
Member

I've think I replicated this locally. I can confirm:

  • The buffer is NULL after writing the file (for me).
  • For my example page the PDF is rendered and around 10 MB in size after saving to the disk.

My best guess on the reason is:

  • It exceeds the maximal length of CLI operations (xargs --show-limits) while passing through. On my system that is around 2 MB. Not entirely sure on this as I'm still working myself into the code.

My first thought on a work-around would be to drop back to the file-system in case of large operations such as generating PDFs or setting content (see #87). This would require to catch the calls/responses and write/load from the FS instead of relying on the passed information.

Does this match your impression @nesk ?

@nesk
Copy link
Member

nesk commented Sep 22, 2020

The communication between PHP and JS is done through sockets, not through CLI operations, I don't thing the limits shown by xargs apply here.

The real issue here is the poor implementation of the socket communication, the problem is described in rialto-php/rialto#12.

Rialto should be entirely agnostic, I don't think we should try to fall back to custom implementations (like the filesystem one) for some specific methods.

@spekulatius
Copy link
Member

Ah okay. Good to know. Learned something more 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants