Goffo.HtmlToPdf 1.2.0

dotnet add package Goffo.HtmlToPdf --version 1.2.0                
NuGet\Install-Package Goffo.HtmlToPdf -Version 1.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Goffo.HtmlToPdf" Version="1.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Goffo.HtmlToPdf --version 1.2.0                
#r "nuget: Goffo.HtmlToPdf, 1.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Goffo.HtmlToPdf as a Cake Addin
#addin nuget:?package=Goffo.HtmlToPdf&version=1.2.0

// Install Goffo.HtmlToPdf as a Cake Tool
#tool nuget:?package=Goffo.HtmlToPdf&version=1.2.0                

HtmlToPdfExportService

This uses the iText7 library. It allows for quick export of an string of html or a byte array of html to a pdf file.

Code Examples

using ExportServices.HtmlToPdfExport.Services;

//***RUN THIS WITHOUT DEBUGGING OR IT WILL THROW A EXCEPTION THAT GETS HANDLED IN iText***

//Create a new service
IHtmlToPdfExportService _service = new HtmlToPdfExportService();

//The PDF File to create
string file = @$"C:\Users\{Environment.UserName}\MyHtmlToPdfFileFromByteArray.pdf";

//Export from existing Byte Array
byte[] bytes = MyMethods.GetMyHtmlBytes(); //You would get this yourself from somewhere...

await _service.ExportHtmlAsPdfFileAsync(bytes, file);

Console.WriteLine("Html to Pdf file created from Byte Array: {0}", file);

//Export from existing html string
file = @$"C:\Users\{Environment.UserName}\MyHtmlToPdfFileFromString.pdf";
string html = MyMethods.GetMyHtml();

await _service.ExportHtmlAsPdfFileAsync(html, file);

Console.WriteLine("Html to Pdf file created from string: {0}", file);

internal static class MyMethods
{
    public static string GetMyHtml()
    {
        return @"<p>My HTML Paragraph to export to PDF</p>";
    }
    public static byte[] GetMyHtmlBytes()
    {
        string html = GetMyHtml();
        System.Text.UTF8Encoding uTF8 = new();
        return uTF8.GetBytes(html);
    }
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 175 3/20/2024
1.1.0 134 2/22/2024
1.0.0 153 1/17/2024

Upgrade to iText 8