Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I Specify PDF Output Path in Chrome Headless Mode

This page shows that you can now use chrome to generate a PDF of a webpage using the following CLI command:

chrome --headless --disable-gpu --print-to-pdf https://www.chromestatus.com/

However, it does not state how to specify the output path.

How do you specify the output path?

like image 376
Cody G Avatar asked Jun 21 '17 16:06

Cody G


People also ask

How do I print to PDF in Chrome?

Open a webpage in Chrome, press Ctrl+P to open the Print dialog and change the destination printer to “Save as PDF”. Hit the “Print” button and the webpage will download as a PDF document. You can also use Chrome's print-to-PDF function to convert to .

Why can't I save as PDF in Chrome?

If you still cannot see the "Save as", then you need to disable the PDF Viewer and revert to Adobe Reader. By doing this, type "about plugins"(without the quotes) in the address bar in Chrome and press Enter. From the plug-in list, you should disable Chrome PDF Viewer and Enable Adobe Reader.

How do I run Chrome in headless mode?

Which command starts the google chrome web browser in headless mode? As we have already seen, you just have to add the flag –headless when you launch the browser to be in headless mode. With CLI (Command Line Interface), just write: chrome \<br> – headless \ # Runs Chrome in headless mode.

What is Google Chrome headless?

Headless mode is a functionality that allows the execution of a full version of the latest Chrome browser while controlling it programmatically. It can be used on servers without dedicated graphics or display, meaning that it runs without its “head”, the Graphical User Interface (GUI).


1 Answers

chrome --headless --disable-gpu --print-to-pdf="C:/temp/pdftest.pdf" https://www.google.com/

source:

enter image description here

https://cs.chromium.org/chromium/src/headless/app/headless_shell.cc?type=cs&l=63

like image 58
Cody G Avatar answered Sep 19 '22 01:09

Cody G