Modern web applications are commonly split up into two major parts. The first part, called the front-end, is the part that most people interact with. The second part, called the back-end, is hidden from users and manages all of the information which is needed by the application. Splitting applications like this sperates the rendering of the information from the generation of the data, which brings certain efficiencies.
HTML to PDF
However, one thing it makes more difficult is rendering non-web formats, like PDFs. Many business applications require report generation and PDF printing, so additional techniques are required to fill this void.
To solve this problem we developed techniques to effciently send the data that the back-end normally generates to a special rendering service rather than sending the data directly back to the front-end. The service generates reports in a web format. Those reports need to be converted to PDF and sent back to the front-end for whoever requested them.
There are ways to generate PDF files directly, but many of those techniques require doing manual layout or using obscure domain specific languages.
We are very proficient at creating pages in web formats, so it is much more efficient to generate reports in those formats. We just need a tool to perform conversion for us.
One of the best tools for creating PDF files from well-formated web pages is Google Chrome. Google has provided a tool called Puppeteer which allows us to write programs that interact with Chrome. So, we used these tools to create another service which can generate high quality PDF files. The technique ensures that the generated PDF files has selectable and searchable text, unlike many other methods of generating PDF files.
Since we know that generating PDf files is a common customer request, we worked to generalize our solution. As a part of that effort we packaged up our PDF generation technique. Putting the code into a package allows us to very quickly add it to future products. It also makes it very easy to upgrade existing products when we improve our solution.
We published this part of our solution so that other developers can also use it. Sharing the solution let's us get feedback from a wider range of developers than we have in-house.
By approaching solutions in this way we are providing value to many of our customers at one time. When we enhance a package for one customer, it becomes fairly trivial to add that enhancement to other client's projects.