Chrome - Save to PDF function use in a website

Chrome allows users to hit Ctrl + P and choose 'Save to PDF'.

Is it possible to have this function through an html button?

I want the user to just hit a button and go directly to the Save as PDF prompt ( where the file name is set by PHP and not automatically by Chrome ). So the user basically just hits the button and clicks on Save on the prompt window.

Is this possible? Can I skip the previous steps?


Nope, it's not possible.

But, you can give the user the choice to download a HTML file output as a PDF file. There are a few libraries around, Prince is the best but expensive, so check out DOMPDF.


By the time your user can hit ctrl+P in the browse, the PHP process that generated the page (on server) is already closed.

Besides the fact that PHP exerts no direct control over browsers. It just sends them information in the form of HTML/CSS and important in this case JavaScript.

With JavaScript you could trigger the normal print behaviour of the browser but you would have no control over it.

Another approach could be to generate the PDF on server and send it as a file to the browser. In which case the browser will either ask the user if he wants to open it or it will ask the user if he wants to download it.

I've personally used fPDF to customise the PDF invoices of various open source e-commerce software. Like for example PrestaShop.

All you really need to do is download the library from (fPDF](http://www.fpdf.org/), but seeing it in action and being able to change/adapt a working version might help you so you could look for the PDF invoice in a fresh the PrestaShop install inside the folder classes the file name is PDF.php .