Skip to content

rafaelmsouza/WkHtmlSmartConvert

Repository files navigation

WkHtmlSmartConvert

Build status Coverage Security Rating

This project implements the conversion of HTML to PDF using wkhtmltopdf. It works only at windows and linux, on x64 arch.

NuGet Packages

Package Version Downloads
WkHtmlSmartConvert NuGet NuGet
WkHtmlSmartConvert.Embedded NuGet NuGet

Packages with suport to .Net Core 2.1, 3.1 and .Net 5.0

Getting Started

  1. Install the standard nuget package into your application.

    dotnet add package WkHtmlSmartConvert
  2. In the ConfigureServices method of Startup.cs, register the WkHtmlSmartConvert.

    services
        .AddWkHtmlSmartConvert()
        .AddPdf();

    or, you can configure global options to every conversion, see PdfOptions.

    services
        .AddWkHtmlSmartConvert()
        .AddPdf(options =>
            {
                options.PageOrientation = PageOrientation.Landscape,
                options.IsGrayScale = true,
                options.Copies = 2,
                options.PageSize = PageSize.A0
            });

Embedded files

The standard configuration looks for wkhtmltopdf installed on host and the environment variable PATH correctly configure, but instead of this, you can use the wkhtmltopdf embedded on the application.

  1. Install the additional nuget package into your application.

    dotnet add package WkHtmlSmartConvert.Embedded
  2. Configure AddEmbedded just after AddWkHtmlSmartConvert.

    services
        .AddWkHtmlSmartConvert()
        .AddEmbedded()
        .AddPdf();

Convert HTML to PDF

You must inject IPdfConvert and call method ConvertAsync

public class ExamplePdfConvert
{
    private readonly IPdfConvert _pdfConvert
    
    public ExamplePdfConvert(IPdfConvert pdfConvert){
        _pdfConvert = pdfConvert;
    }

    public async Task<byte[]> GeneratePdfAsync() { 
        var buffer = await _pdfConvert.ConvertAsync("<html>Hello World!</html>");
        return buffer;
    }
}

About

This project implements the conversion of HTML to PDF, working in windows and linux only on x64 arch.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages