HtmlToPdf2AZ 1.0.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 and Polyglot Notebooks. 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 Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.0.1 535 7/22/2022
1.0.0 419 7/21/2022