

The Puppeteer comes from the NodeJS world, and the Puppeteer Sharp is a port to. Wait what… haven’t I seen this in the Javascript world? Let me introduce you to the Puppeteer Sharp. This is the moment you have been waiting for. You would like to create the PDF, but most of the libraries are paid, and they cost A LOT.Īlso, when you manage to find a free version or open-source version of a library, it is not supported anymore, or it does not work the way you expect. The Problem: Generating PDF From HTML in. NET Core applications is not straightforward. The most convenient way to do it would be to create HTML templates and then convert them into PDF. It can be a small or enterprise application: at some point, you will benefit from generating PDF files. No matter what kind of application you are creating.

This code was effortless to slip into their automation script, and successfully generated PDF versions of their invoices. Converting a HTML document to PDF was a simple as this: var browserFetcher = new BrowserFetcher() Īwait using var browser = await Puppeteer.LaunchAsync(new LaunchOptions ) Īwait using var page = await browser.NewPageAsync() Īwait page.GoToAsync("file://path/of/the/invoice.html") NET port of Puppeteer called Puppeteer Sharp.

NET (which was why they asked me for help), so they didn't want to deal with the Node version. The freelancer's tech stack of choice was. Puppeteer runs headless by default, but can be configured to run full (non-headless) Chrome or Chromium. Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. This isn't the type of task I usually do, but my first instinct was to use Puppeteer. The freelancer's existing workflow was to manually open each invoice in Chrome, and use the "Print to PDF" functionality to generate a PDF. They'd automated everything up until that point, but some of their clients wanted the invoices sent as PDF documents. They were tech savvy, and were using a templating engine to generate beautiful HTML documents from a template and some data files. I recently had a freelancer ask me for help with the automated generation of their invoices.
