Implement Page.printToPDF
Categories
(Remote Protocol :: CDP, task, P1)
Tracking
(firefox73 fixed)
Tracking | Status | |
---|---|---|
firefox73 | --- | fixed |
People
(Reporter: whimboo, Assigned: whimboo)
References
(Blocks 4 open bugs, )
Details
(Whiteboard: [puppeteer-beta-mvp])
Attachments
(1 file)
(deleted),
text/x-phabricator-request
|
Details |
Implementation bug for the Page.printToPDF
method. Taking the puppeteer-alpha whiteboard entry from the meta bug.
Assignee | ||
Comment 1•5 years ago
|
||
I will have a look if it's implementable. See also the comment which I made on the meta bug before:
(In reply to Henrik Skupin (:whimboo) [⌚️UTC+2] from bug 1549479 comment #1)
Note that there is a WebExtension API which allows to do that for add-ons:
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/saveAsPDFIt's implementation can be found here:
https://searchfox.org/mozilla-central/rev/11d9c7b7fa82fdfb8ac2a8f0864e9d8d5fe2b926/browser/components/extensions/parent/ext-tabs.js#1304It uses the underlying PrintSettingsService to print the document to a PDF file. I assume that we could make use of it too.
Assignee | ||
Comment 2•5 years ago
|
||
I got the implementation working, which basically prints the document to a PDF file. By default Puppeteer uses ReturnAsStream
for the transferMode
, which means we need IO.read
and IO.close
implemented too. Once those are done, we will have the ReturnAsBase64
for free.
Assignee | ||
Comment 3•5 years ago
|
||
One interesting problem I noticed when implementing the ReturnAsBase64
transfer mode is that even when printing is done, the chosen PDF file hasn't been finished writing yet. To prevent race conditions we will have to wait until all the data has been written. I will use a timer for that and check with an interval of 100ms if that is the case.
Remaining work to do on this bug is to write some tests.
Assignee | ||
Comment 4•5 years ago
|
||
Comment 5•5 years ago
|
||
https://github.com/gramener/gramex/tree/dev/gramex/apps/capture is a real world use of print to PDF that we should test and see how we compare.
Assignee | ||
Comment 6•5 years ago
|
||
(In reply to David Burns :automatedtester from comment #5)
https://github.com/gramener/gramex/tree/dev/gramex/apps/capture is a real world use of print to PDF that we should test and see how we compare.
PDF generation works fine with this tool once Network.getCookies
, Network.deleteCookie
, Network.setExtraHTTPHeaders
and Emulation.setEmulatedMedia
have been implemented. Do we want to have meta bugs for different tools, so we can easily mark dependencies?
Assignee | ||
Comment 7•5 years ago
|
||
Assignee | ||
Comment 8•5 years ago
|
||
I will file the bugs for the capture.js tool and mark its dependencies.
Assignee | ||
Comment 9•5 years ago
|
||
Here another try which includes the addition two await
s that I was missing before, and which probably caused the IO tests on Windows to fail:
https://treeherder.mozilla.org/#/jobs?repo=try&revision=22b90f00c1ee24e0297637a8548bacffd5b8c376
Assignee | ||
Comment 10•5 years ago
|
||
The clean-up function fails on Windows to remove the temporary files if those are still open. As such we should attempt to close them first:
https://treeherder.mozilla.org/#/jobs?repo=try&revision=f4482289b579d8a01b32be876e28e3256bcc7795
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Comment 11•5 years ago
|
||
Comment 12•5 years ago
|
||
bugherder |
Updated•4 years ago
|
Description
•