简体   繁体   中英

puppeteer-sharp for server side HTML to PDF conversions

I found that puppeteer sharp is best way for server side, HTML to PDF conversion as it uses and downloads latest chrome and runs headless in background so the conversion is top class. tables and all else is rendered perfectly.

However for running on server, how should the concurrency be managed, because i think each web site users conversion request will launch another chrome instance. how does puppeteer sharp manages concurrency.

is is better to split it as separate web service and enqueue conversion requests and pass all pdf related requests to be served on one by one basis instead of running into concurrency or resource issues on webserver for multiple chrome instances.

I found this is the most scalable way to implement this is by using a background process. This is one real-life example:

  1. A WebClient request a PDF sending a signalR message.
  2. The SignalR hub creates some kind of an ID, put the request in an Azure Queue, and adds the SignalR client to a SignalR group with that ID.
  3. A console app would read that queue, process the HTML, and sends back the result to the server using a SignalR message.
  4. The WebServer will get the message, and broadcast that message to all the clients in that group.

It might sound quite complicated, but it's not that much. You can make it simpler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM