How to delay print to PDF?

3,224 views
Skip to first unread message

ofer...@gmail.com

unread,
Jul 27, 2017, 1:46:25 AM7/27/17
to headless-dev
Hi,

I am using headless chromium on Windows 10 (Version 62.0.3166.0 (Developer Build) (64-bit)) to print a web application report running on Tomcat/Java server and angular 2 client into a PDF file (product in development)

If I'm using this:

chrome --headless --disable-gpu --print-to-pdf=my.pdf https://angular.io

I get a the PDF result just fine.

But when running locally to the Tomcat/Java server:

chrome --headless --disable-gpu  --print-to-pdf=my.pdf http://localhost/report/1

I get an empty PDF file (no content).

My guess is that the specific report page takes longer to render, as it has to make few REST calls to the server to build the report.

My question: is there any way to add a delay in Chromium before printing to PDF?

I also tried to run nodeJS wrapper code such as: simple-headless-chrome, but it uses Chrome and not Chromium, so it's not good for me.

Any idea would be greatly welcome!

Thx

Ofer

Alex Clarke

unread,
Jul 27, 2017, 3:36:26 AM7/27/17
to ofer...@gmail.com, headless-dev
On 27 July 2017 at 06:46, <ofer...@gmail.com> wrote:
Hi,

I am using headless chromium on Windows 10 (Version 62.0.3166.0 (Developer Build) (64-bit)) to print a web application report running on Tomcat/Java server and angular 2 client into a PDF file (product in development)

If I'm using this:

chrome --headless --disable-gpu --print-to-pdf=my.pdf https://angular.io

I get a the PDF result just fine.

But when running locally to the Tomcat/Java server:

chrome --headless --disable-gpu  --print-to-pdf=my.pdf http://localhost/report/1

I get an empty PDF file (no content).

My guess is that the specific report page takes longer to render, as it has to make few REST calls to the server to build the report.
Are you sure a delay would help? The pdf isn't printed until the Page.loadEventFired is sent.  Could the problem be something else?
 

My question: is there any way to add a delay in Chromium before printing to PDF?

Generally we don't want to add too many command line switches, particularly when there's overlap with what can be done via devtools api.
 

I also tried to run nodeJS wrapper code such as: simple-headless-chrome, but it uses Chrome and not Chromium, so it's not good for me.
 
Why would that be a problem? Chrome supports --headless.

 

Any idea would be greatly welcome!

Thx

Ofer

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev+unsubscribe@chromium.org.
To post to this group, send email to headle...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/headless-dev/eefea84d-f2ce-484d-b7b7-ebca1ecce83c%40chromium.org.

עופר בר

unread,
Jul 27, 2017, 5:18:39 AM7/27/17
to headless-dev, ofer...@gmail.com
Chromium is open source  - this is a licensing /distribution issue.

I think we need find a way in the app to delay Page.loadEventFired so that the entire data for rendering is fetched.

Thanks!


On Thursday, July 27, 2017 at 10:36:26 AM UTC+3, Alex Clarke wrote:
On 27 July 2017 at 06:46, <ofer...@gmail.com> wrote:
Hi,

I am using headless chromium on Windows 10 (Version 62.0.3166.0 (Developer Build) (64-bit)) to print a web application report running on Tomcat/Java server and angular 2 client into a PDF file (product in development)

If I'm using this:

chrome --headless --disable-gpu --print-to-pdf=my.pdf https://angular.io

I get a the PDF result just fine.

But when running locally to the Tomcat/Java server:

chrome --headless --disable-gpu  --print-to-pdf=my.pdf http://localhost/report/1

I get an empty PDF file (no content).

My guess is that the specific report page takes longer to render, as it has to make few REST calls to the server to build the report.
Are you sure a delay would help? The pdf isn't printed until the Page.loadEventFired is sent.  Could the problem be something else?
 

My question: is there any way to add a delay in Chromium before printing to PDF?

Generally we don't want to add too many command line switches, particularly when there's overlap with what can be done via devtools api.
 

I also tried to run nodeJS wrapper code such as: simple-headless-chrome, but it uses Chrome and not Chromium, so it's not good for me.
 
Why would that be a problem? Chrome supports --headless.

 

Any idea would be greatly welcome!

Thx

Ofer

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.

Eric Seckler

unread,
Jul 27, 2017, 5:26:22 AM7/27/17
to עופר בר, headless-dev
Interacting via chrome-remote-interface and node should be possible with a chromium build. Then, you should be able to determine the right point to print the PDF using your own logic, e.g. by adding a simple delay in your client code or using DevTools to track resource fetching events or alike :)

Using the command line options alone will probably not be sufficient for your use case.

ofer...@gmail.com

unread,
Aug 2, 2017, 7:31:34 AM8/2/17
to headless-dev, ofer...@gmail.com
Just to update about this issue, maybe it will help others:

I've tried the chrome-remote-interface but got various errors using it so I gave up.

Eventually we found this node package: html-pdf-chrome which is working fine.

Thanks to all who responded!

luc...@getsirena.com

unread,
Aug 10, 2017, 12:58:51 AM8/10/17
to headless-dev, ofer...@gmail.com
Hi! 

If you use simple-headless-chrome, and you need Chromium instead of Chrome, you can instance the browser passing the "chromePath" for your Chrome/Chromium binary. 
Just pass it as an option like this: 

const browser = new HeadlessChrome({ headless: true, chrome: { chromePath: 'YOUR_CHROME_PATH' } })

About the time you have to wait for rendering, just check how this example makes use of the "wait" method: https://github.com/LucianoGanga/simple-headless-chrome/blob/master/examples/postInMedium.js

I hope it helps, 

Cheers!
Lucho

oscarl...@gmail.com

unread,
Aug 14, 2017, 4:52:53 AM8/14/17
to headless-dev, ofer...@gmail.com
html-pdf-chrome doesn't work for ajax calls, the CompletionTrigger (Timer, Element etc) even doing what suppose to be doing; doesn't render the areas rendered asynchronously. I think this is an open issue with headless

vhilly....@gmail.com

unread,
Oct 10, 2017, 12:35:55 AM10/10/17
to headless-dev, ofer...@gmail.com
Hi I also encountered unrendered angular values. Do you have solution now? I have a temporary solution. I placed an image at the end of html, I make sure image is quite large so that when the page completely loads its assets including the large image the angular already processed the data.

Luca Fagioli

unread,
Mar 20, 2023, 11:21:22 AM3/20/23
to headless-dev, vhilly....@gmail.com, ofer...@gmail.com
virtual-time-budget is the parameter you need. It defines in milliseconds the time to wait before rendering. Example:

--virtual-time-budget=2000

Jerry Lee Daniel

unread,
Nov 19, 2023, 11:06:56 AM11/19/23
to headless-dev, Luca Fagioli, vhilly....@gmail.com, ofer...@gmail.com
Loans, Project and Digital Investment financing available up to $500m.
Have a Business Plan, Fundable Project and Redeemable Collateral.

Whatsapp: +44 7405 896213
Reply all
Reply to author
Forward
0 new messages