delight-im / HTML-Sheets-of-Paper

Word processor in your browser using HTML and CSS (for invoices, legal notices, etc.)
https://delight-im.github.io/HTML-Sheets-of-Paper/
MIT License
1.22k stars 142 forks source link

Render To PDF #8

Closed zicklag closed 3 years ago

zicklag commented 3 years ago

Feel free to close this if it's like something that is fundamentally unsupported by browsers, but I was curious if there was a way to skip the printing step and go immediately to producing a PDF, identical in concept to manually "Print to File", but nicer from a user experience. I'm feeling like it's impossible from what I can find, but I wanted to ask just to make sure. :)

ocram commented 3 years ago

You could certainly turn the DOM/HTML+CSS into an image first, e.g. using https://github.com/niklasvh/html2canvas, and then embed that image into a PDF file, e.g. using https://github.com/MrRio/jsPDF – all on the client side. But that way, you’ll probably lose the ability to search or highlight text.

On the other hand, on the server side, it’s easy to do via headless Chrome, etc.

Does that help?

zicklag commented 3 years ago

Those are great options I had considered, and server side rendering is probably my best bet.

I think I'm going with a different strategy for my app anyway now, and I'm pretty sure this is simply a browser limitation not a limitation of your app so I'll close this now. Thanks! :slightly_smiling_face: