Documentation

DGtalSharp.PDF

DGtalSharp.Pdf is a cross platform .Net component which creates pdf from html. Its based-on Chromium engine and supports latest html/css syntax. 


Getting Started

Add nuget package

Install nuget package DGtalSharp.Pdf

Install-Package DGtalSharp.Pdf

Set License Key

Set license key if you have one or you can buy from home page. To set license key in your startup, add following line

DGtalSharp.Pdf.LicenseManager.SetLicense("LICENSE_KEY");

Replace "LICENSE_KEY" with actual key received in email.

Initialize (Optional but Recommended)

It's recommended that you initialize Pdf component on startup as it may take time to setup required system components. DGtalSharp.Pdf may download some prerequisites from internet if its not already available on the target system. 

await PdfInitializer.Initialize();

It will download and install all pre-requisites on the target system.

Note: If you are working offline or without internet, you can configure it to work offline without internet. See 'Offline' section in documentation for available options.

Create PDF from HTML

Adding using in namespaces

using DGtalSharp.Pdf;

Now you are all set. Simply create pdf now by single line


To create Pdf from URL

var stream = await HtmlDocument.GetPdfStreamFromUrl(url); 

To create Pdf from URL

var stream = await HtmlDocument.GetPdfStreamFromUrl(url); 

Pdf Stream can be saved to file

stream.SaveToFile("C:\\Document.pdf"); 

or can read bytes from stream

var bytes = stream.ToBytes(); 

Stream can be returned as download-able file from web app/controllers

return File(stream, "application/pdf", "Document.pdf"); 

Summary


//install nuget package
Install-Package DGtalSharp.Pdf

//initialize 
await PdfInitializer.Initialize();

//add using 
using DGtalSharp.Pdf;

//create pdf from url
var stream = await HtmlDocument.GetPdfStreamFromUrl(url); 

//save to file
stream.SaveToFile("C:\\Document.pdf");