Hope this post can save you some time in this endeavor! Prerequisites However, even after working down this path, I still found myself in trial and error mode, with only a handful of tutorials available to help in my journey. Hence, I was thrilled to learn of the Puppeteer browser via the Chrome team. I went down the path of using PhantomJs as a headless browser to print PDFs several years ago, and remember ultimately not being successful. Even simply getting the size and margins right can be a painful struggle. Its basically a picture printed on one pdf page. This option does not support multiple paged pdfs or page breaks very well, nor does it preserve the text data very well. Canvas is essentially an image on a pdf page. This one was able to convert html to canvas without errors. jsPDF - Another great javascript library that generates pdfs.I did not want to rewrite my entire html into an object array, so instead I spent many hours trying to convert html to canvas, but could not get past error messages from the canvas size. PDFMake - A great javascript library that generates pdf from an object array. ![]() In efforts to save you from that, here's what did not work for me, and why: ![]() ![]() ![]() In my efforts to find a good method to print html to PDF, I ran into many dead ends. That may initially sound strange, but they are great for automating PDF rendering, or creating a robot to search the web. So what's a headless browser? Simply put, its a browser with no display. Big thanks to the Chrome DevTools team for maintaining this excellent headless browser! We will be using the Puppeteer headless chrome browser to pull the web page on a Node server and convert it to PDF. This article shares a brief tutorial for how to save web page as PDF with NodeJs.
0 Comments
Leave a Reply. |