Gangmax Blog

自由之思想,独立之精神

Export Web Page to PDF With Headless Google Chrome

| Comments

Headless browsers provide automated control of a web page in an environment similar to popular web browsers, but are executed via a command-line interface or using network communication. They are particularly useful for testing web pages as they are able to render and understand HTML the same way a browser would, including styling elements such as page layout, colour, font selection and execution of JavaScript and AJAX which are usually not available when using other testing methods.

PhantomJS is a headless browser. Firefox and Chrome can also work in headless mode. The following command uses headless Chrome to export web page into PDF file(from here):

1
oogle-chrome --headless --disable-gpu --print-to-pdf http://gangmax.me/blog/archives/

The command will generate an “output.pdf” file in your current directory which contains the web page content.

Comments