HtmlToPdf2AZ 1.0.1

.NET Standard 2.1
dotnet add package HtmlToPdf2AZ --version 1.0.1
NuGet\Install-Package HtmlToPdf2AZ -Version 1.0.1
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="HtmlToPdf2AZ" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HtmlToPdf2AZ --version 1.0.1
#r "nuget: HtmlToPdf2AZ, 1.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install HtmlToPdf2AZ as a Cake Addin
#addin nuget:?package=HtmlToPdf2AZ&version=1.0.1

// Install HtmlToPdf2AZ as a Cake Tool
#tool nuget:?package=HtmlToPdf2AZ&version=1.0.1

HtmlToPdf2AZ

NuGet

HtmlToPdf2AZ is a simple library for generating PDFs from html or from url.

Main methods

  • GetPDFFromHTML: use that method to convert an HTML to Stream PDF
  • GetPDFFromURL: use that method to convert an url content to Stream PDF

Example of use

Console APP

	static void Main(string[] args)
    {
        var pdf = new HtmlToPdf2AZ.PdfTools();
        string outputFile = @"C:\myfile.pdf";
        string outputFile2 = @"C:\mifile2.pdf";
        var res = pdf.GetPDFFromHTML("<p style='font-size:20px;'>Hello world</p>",
            headerTemplate: "<div class=\"header\" style=\"padding: 10px; -webkit-print-color-adjust: exact; background-color: red; colour: white; width: 100%; text-align: left; font-size: 12px;\">Header goes here<br /><br /><br /> Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\" ></span></div>",
            footerTemplate: "<div class=\"footer\" style=\"padding: 10px; -webkit-print-color-adjust: exact; background-color: blue; colour: white; width: 100%; text-align: right; font-size: 12px;\">Here goes the footer<br /><br /><br /> Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\ "></span></div>",
            marginOptions: new HtmlToPdf2AZ.Models.MarginOptions("50"),
            paperFormat: HtmlToPdf2AZ.Models.PaperFormat.A4).Result;
        var res2 = pdf.GetPDFFromURL("https://www.google.es",
            headerTemplate: "<div class=\"header\" style=\"padding: 0 !important; edge: 0; -webkit-print-color-adjust: exact; background-color: red; colour: white; width: 100%; text-align: left; font-size: 12px;\">header of John<br /> Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></div> ",
            footerTemplate: "<div class=\"footer\" style=\"padding: 0 !important; edge: 0; -webkit-print-color-adjust: exact; background-color: blue; colour: white; width: 100%; text-align: right; font-size: 12px;\">footer of John<br /> Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></div> ",
            marginOptions: new HtmlToPdf2AZ.Models.MarginOptions("50"),
            paperFormat: HtmlToPdf2AZ.Models.PaperFormat.A4).Result;
        SaveFileStream(outputFile, res);
        SaveFileStream(outputFile2, res2);
    }
    private static void SaveFileStream(string path, Stream stream)
    {
        var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write);
        stream.CopyTo(fileStream);
        fileStream.Dispose();
    }

MVC ActionResult

	public async Task<ActionResult> DownloadPDF()
    {
        HtmlToPdf2AZ.PdfTools pdfTools = new HtmlToPdf2AZ.PdfTools();
        var res = await pdfTools.GetPDFFromHTML("<p style='font-size:20px;'>Hello world</p>",
            headerTemplate: "<div class=\"header\" style=\"padding: 10px; -webkit-print-color-adjust: exact; background-color: red; colour: white; width: 100%; text-align: left; font-size: 12px;\">Header goes here<br /><br /><br /> Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\" ></span></div>",
            footerTemplate: "<div class=\"footer\" style=\"padding: 10px; -webkit-print-color-adjust: exact; background-color: blue; colour: white; width: 100%; text-align: right; font-size: 12px;\">Here goes the footer<br /><br /><br /> Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\ "></span></div>",
            marginOptions: new HtmlToPdf2AZ.Models.MarginOptions("50"),
            paperFormat: HtmlToPdf2AZ.Models.PaperFormat.A4);
        return new FileStreamResult(res, "application/pdf")
        {
            FileDownloadName = "test.pdf"
        };
    }

License

MIT

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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.0.1 179 7/22/2022
1.0.0 191 7/21/2022