Many documents
HtmlToPdf is static and thread-safe: one call per document, on as many threads as you use. There is nothing to start, pool or keep alive: no browser process, no page to recycle.
Many documents at once
Parallel.ForEach(invoices, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }, invoice =>
{
var result = HtmlToPdf.Render(invoice.Html, options);
File.WriteAllBytes(invoice.Path, result.Pdf!);
});
In a web application, RenderAsync runs a render on the thread pool. A cancellation stops a render that has not started; one under way runs to its end or its limits.
Large documents
- Render(html, stream) writes the PDF to a stream (a file, a response) instead of returning its bytes.
- Compression trades size for time: Fastest by default, Smallest for files kept long. See the sizes.
- MaxPages and the other limits keep a runaway page from filling memory.
Speed
Speed figures will be published here once measured on a quiet machine, with the date and the method.