Print PDF headless chrome in a java program

2,906 views
Skip to first unread message

balaku...@gmail.com

unread,
Nov 14, 2017, 11:11:58 AM11/14/17
to headless-dev

Hi All,


How to print pdf in selenium headless chrome driver in a java program? There are few examples by using "--print-to-pdf" option. 

But this isn't working in a java program, could someone help me in this?



Thanks in advance! ~Balakumar

Jianzhou Feng

unread,
Nov 14, 2017, 7:21:56 PM11/14/17
to balaku...@gmail.com, headless-dev
I guess there is no print to pdf method you can call from Chromedriver, you may need to ask for the chromedriver people to add a new method for the pdf case.

Another option is: let your program run chrome with --headless --print-to-pdf=/path/to/your/file, it should output the pdf file and exit chrome after doing that. 
Note that --print-to-pdf uses default printing settings that you can't change.

--
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/6ed7ed5e-2f6a-4cab-bfa0-6dbec12269da%40chromium.org.

balaku...@gmail.com

unread,
Nov 14, 2017, 11:42:17 PM11/14/17
to headless-dev, balaku...@gmail.com
Hi,

Ok, I saw few examples to make this work in Mac OS like shown in this link: https://developers.google.com/web/updates/2017/04/headless-chrome

But could some one show me how to make this work in windows, I tried with a .bat file in windows like following didn't work.


SET "chrome=C:\Program Files (x86)\Google\Chrome\Application"

%chrome% --headless --disable-gpu --print-to-pdf="C:\Users\bseethap\Desktop\temp" https://www.chromestatus.com/

PAUSE

thanks for your help in advance!

Regards,
Balakumar






On Wednesday, November 15, 2017 at 5:51:56 AM UTC+5:30, Jianzhou Feng wrote:
I guess there is no print to pdf method you can call from Chromedriver, you may need to ask for the chromedriver people to add a new method for the pdf case.

Another option is: let your program run chrome with --headless --print-to-pdf=/path/to/your/file, it should output the pdf file and exit chrome after doing that. 
Note that --print-to-pdf uses default printing settings that you can't change.
On Wed, Nov 15, 2017 at 3:11 AM, <balaku...@gmail.com> wrote:

Hi All,


How to print pdf in selenium headless chrome driver in a java program? There are few examples by using "--print-to-pdf" option. 

But this isn't working in a java program, could someone help me in this?



Thanks in advance! ~Balakumar

--
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.

Jianzhou Feng

unread,
Nov 15, 2017, 12:17:29 AM11/15/17
to balaku...@gmail.com, headless-dev
Try:

SET "chrome=C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"

"%chrome%" --headless --disable-gpu --print-to-pdf="C:\Users\bseethap\Desktop\temp.pdf" https://www.chromestatus.com/

PAUSE


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.

balaku...@gmail.com

unread,
Nov 15, 2017, 12:25:06 AM11/15/17
to headless-dev, balaku...@gmail.com
Hi,

thanks for your help! Silly Me!! lot of typos..

Regards,
Balakumar
Reply all
Reply to author
Forward
0 new messages