- Notifications
You must be signed in to change notification settings - Fork4
C# .NET Core wrapper for wkhtmltopdf library that uses Webkit engine to convert HTML pages to PDF.
License
simplcommerce/DinkToPdf
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
.NET Core P/Invoke wrapper for wkhtmltopdf library that uses Webkit engine to convert HTML pages to PDF.
Library can be installed through Nuget. Run command bellow from the package manager console:
PM> Install-Package DinkToPdf
Copy native library to root folder of your project. From there .NET Core loads native library when native method is called with P/Invoke. You can find latest version of native libraryhere. Select appropriate library for your OS and platform (64 or 32 bit).
Library was NOT tested with IIS. Library was tested in console applications and with Kestrel web server both for Web Application and Web API .
Use this converter in single threaded applications.
Create converter:
varconverter=newBasicConverter(newPdfTools());
Use this converter in multi threaded applications and web servers. Conversion tasks are saved to blocking collection and executed on a single thread.
varconverter=newSynchronizedConverter(newPdfTools());
vardoc=newHtmlToPdfDocument(){GlobalSettings={ColorMode=ColorMode.Color,Orientation=Orientation.Landscape,PaperSize=PaperKind.A4Plus,},Objects={newObjectSettings(){PagesCount=true,HtmlContent=@"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In consectetur mauris eget ultrices iaculis. Ut odio viverra, molestie lectus nec, venenatis turpis.",WebSettings={DefaultEncoding="utf-8"},HeaderSettings={FontSize=9,Right="Page [page] of [toPage]",Line=true,Spacing=2.812}}}};
If Out property is empty string (defined in GlobalSettings) result is saved in byte array.
byte[]pdf=converter.Convert(doc);
If Out property is defined in document then file is saved to disk:
vardoc=newHtmlToPdfDocument(){GlobalSettings={ColorMode=ColorMode.Color,Orientation=Orientation.Portrait,PaperSize=PaperKind.A4,Margins=newMarginSettings(){Top=10},Out=@"C:\DinkToPdf\src\DinkToPdf.TestThreadSafe\test.pdf",},Objects={newObjectSettings(){Page="http://google.com/",},}};
converter.Convert(doc);
Converter must be registered as singleton.
publicvoidConfigureServices(IServiceCollectionservices){// Add converter to DIservices.AddSingleton(typeof(IConverter),newSynchronizedConverter(newPdfTools()));}
About
C# .NET Core wrapper for wkhtmltopdf library that uses Webkit engine to convert HTML pages to PDF.
Resources
License
Stars
Watchers
Forks
Packages0
Languages
- C#100.0%