Puppeteer is not the only package to give this ability Microsoft also have their own offering called Playwright, which shares much of the same functionality of Puppeteer, whilst also giving the option for using other browsers (which makes it a really good candidate for automated testing). Puppeteer is a headless (chromium) browser that comes with an easy-to-consume API that allows you to control a chromium instance programmatically. So, this is where Puppeteer comes in, this should allow us to navigate to a given page and generate a PDF report and download to the client. We really wanted to give consistent results across all users and browsers. We can quickly verify that this works as expected locally, however we did find that we would get differing results across different browsers and versions. That left us with trying to use the browsers existing print to PDF function along with print specific CSS to create a PDF. We decided to not pursue these for now as the level of work required was either too high or the costs were too high to pursue at this early stage. We did look at a few third-party packages for generating PDFs, however much of these had costs associated with them or needed their own markdown which would need to be maintained separately to the main report. Use a third-party PDF generation application However as most of these reports would span more than one page, getting around the formatting issues was deemed to be too much work for the moment.Ģ. Some experiments with this looked promising. Why Puppeteerīefore settling on Puppeteer we did look at a few other options:Īt a basic level this would create an image using the HTML Canvas that we could then save as a PDF on the client side. For the frontend we are using reactjs with typescript. The Development Project's Tech Stackįor the API the project uses Node.js and hapi with typescript. When generating a PDF, we need to be able to maintain these report filters and options so a user can generate exactly what they have selected. All these reports have extensive filters and options that change what data is shown and how it is shown. In a recent project we had a requirement to add in the option to generate PDFs to an already extensive reporting tool built using React. Developing Software to Generate PDFs: The Background
0 Comments
Leave a Reply. |