3

I am looking to use the google chrome headless browser's 'print to pdf' functionality to replace an existing way (using iText) to generate PDFs.

Is this a feasible solution considering the number of concurrent calls that would need to be processed is unknown?

Is headless browser's print to pdf functionality used in production for enterprise solutions to generate PDFs/screenshots or is it mainly meant for testing and development environments?

If processing multiple concurrent calls from a single machine would be an issue, would a serverless solution based on AWS lambda be a good way to approach this because of the scalability and the ability to do parallel processing?

uday kiran
  • 299
  • 1
  • 2
  • 9

1 Answers1

0

I used the lambda functions for creating PDF files and it works fine. Scalability and parallel process also works as well because it is AWS lambdas. But while I creating the working solution a got a lot of problems.

First of all, I used AWS API Gateway as a trigger for the lambda and I got a 30-sec timeout for the API request. This means time was limited.

My first solution was usage "chrome-aws-lambda" and "puppeteer-core" nodeJS libraries.

The very slow solution, if be honest. And very painful from the architecture side. User UI -> request to back for PDF -> lambda function run the headless browser -> [ headless chrome start -> open some page -> request to the back for some data] -> wait for loading -> create snapshot -> response with PDF

Then I tried some libraries and stoped on "dynamic-html-pdf". This lib uses "handlebars" template and "html-pdf" lib as engine. If you have not some dynamic data on the page (f.e. dynamic list of items or some if statements) - you can use "html-pdf" only.

persononomo
  • 101
  • 7