Wednesday, January 9, 2019

How to convert html to pdf using Puppetter from dotnet Core

Puppetter is a nodejs library developed by google which calls chromium on the background to do certain tasks. One of this tasks can be convert an html document/url into a pdf.
Since we want to use this feature from dotnet core C# there are a few steps that we must follow.

First we need the nutget package for NodeServices
Install-Package Microsoft.AspNetCore.NodeServices

Then we need to enable this NodeServices on our Startup.cs

Install required node packages

npm init
npm install puppetter
npm install fs-extra
npm install uuid

Create a puppetter.js file on your solution with this contents.
Now everything is set, only step required is to call the module from C#.

No comments:

Post a Comment