The components of a React application are dynamic whereas a PDF is a static file.To adapt your code for printing, you have to bypass the 2 main differences between a web page and a PDF: However, the feedback loop is not as quick as usual. You can make your changes to your code as usual, and then ctrl+P on your page to see what it looks likes: Render a printable version of your pageįor this part you don't actually need to have Puppeteer or any other printer service set up. Then, I will show you how to use Puppeteer for the generation of your new printable page. Firstly, I will explain to you how you can create a printable version of your page with React and Puppeteer. In this article, I want to give you a few tips to generate beautiful PDFs of SPAs with Puppeteer. Indeed, there are easier solutions for this use case like wkhtmltopdf, html-pdf-node or jspdf for example. It may not be so if you don't deal with javascript bundles but with plain HTML/CSS. According to me, it is the easiest way to deal with PDF generation of Single Page Applications. But my choice went naturally to the well-known, google-developed library: Puppeteer. That's when I said "ok this feature may be worth it", but how should I do it? There are many open source libraries that can generate PDFs.
0 Comments
Leave a Reply. |