![]() |
VOOZH | about |
dotnet add package Sats.Core.HTMLToPdf --version 2.0.0
NuGet\Install-Package Sats.Core.HTMLToPdf -Version 2.0.0
<PackageReference Include="Sats.Core.HTMLToPdf" Version="2.0.0" />
<PackageVersion Include="Sats.Core.HTMLToPdf" Version="2.0.0" />Directory.Packages.props
<PackageReference Include="Sats.Core.HTMLToPdf" />Project file
paket add Sats.Core.HTMLToPdf --version 2.0.0
#r "nuget: Sats.Core.HTMLToPdf, 2.0.0"
#:package Sats.Core.HTMLToPdf@2.0.0
#addin nuget:?package=Sats.Core.HTMLToPdf&version=2.0.0Install as a Cake Addin
#tool nuget:?package=Sats.Core.HTMLToPdf&version=2.0.0Install as a Cake Tool
This package allows you to convert HTML files to PDF using the Chrome executable. It leverages Chrome's headless mode to generate PDFs from local or remote HTML files efficiently.
To install this package, follow these steps:
Download the latest .nupkg file from the GitHub Releases page, or use NuGet Package Manager in Visual Studio or the .NET CLI:
dotnet add package HtmlToPdf --version 2.0.0
Include the Required Dependencies:
Below is an example of how to use the package to convert an HTML file to PDF.
using System;
using System.IO;
class Program
{
static void Main(string[] args)
{
// Path to the HTML file you want to convert
var url = @"d:\3bc00512-c01a-4f6d-a26e-77616ef51807.html";
// Path to your Chrome executable
var chromePath = @"C:\Program Files\Google\Chrome\Application\chrome.exe";
// Use the ChromeOptions class to set conversion options
var output = new ChromeOptions().AddOptions(b =>
{
// Set Chrome to headless mode (no UI)
b.Headless();
// Disable GPU (optional)
b.DisableGPU();
// Remove header and footer from the generated PDF
b.WithoutHeader();
}).ToPdf(new ChromeDetails()
{
ChromePath = chromePath, // Path to Chrome executable
HtmlPath = url, // Path to HTML file
DeleteOutputFile = true, // Delete temporary output file after conversion (optional)
UserDirectoryPath = "d:\\userdir" // Path for Chrome's user data directory (optional)
});
// Save the generated PDF to the specified path
File.WriteAllBytes(@"d:\print.pdf", output.FileDetails.File);
}
}
HtmlPath: The file path of the HTML document you want to convert to PDF.
"d:\\3bc00512-c01a-4f6d-a26e-77616ef51807.html"ChromePath: The file path to your Google Chrome executable.
"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"DeleteOutputFile: A boolean flag to specify whether the temporary output file (during the conversion process) should be deleted.
trueUserDirectoryPath: Optional path where Chrome will store user data during the conversion process (used for handling cookies, cache, etc.).
"d:\\userdir"Headless Mode: The Headless() option allows Chrome to run in headless mode, meaning no graphical user interface (GUI) is shown.
Disable GPU: The DisableGPU() option can be used to disable the GPU hardware acceleration.
Remove Header/Footer: The WithoutHeader() option removes any page numbers, date, or URL that Chrome normally adds to the PDF.
d:\print.pdf.Issue: No PDF Generated
ChromePath property.Issue: Header/Footer Still Appears
WithoutHeader() option. If the problem persists, check if any default settings in Chrome override this option.Issue: Permissions Error
HtmlPath and output files (d:\print.pdf) are accessible and writable.This package is licensed under the MIT License.
If you encounter any issues or have questions, feel free to open an issue on the GitHub repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 is compatible. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.1 netcoreapp3.1 is compatible. |
Showing the top 1 NuGet packages that depend on Sats.Core.HTMLToPdf:
| Package | Downloads |
|---|---|
|
Meddata.LibraryHelpers
Package Description |
This package is not used by any popular GitHub repositories.
Usage
var url = @"d:\convert.html";
var chromePath = @"C:\Program Files\Google\Chrome\Application\chrome.exe";
var output = new ChromeOptions().AddOptions(b =>
{
b.Headless();
b.DisableGPU();
b.WithoutHeader();
}).ToPdf(new ChromeDetails()
{
ChromePath = chromePath,
HtmlPath = url,
DeleteOutputFile = true, //optional
// OutputPath = @"d:\print.pdf" // (add if Environment.CurrentDirectory does not have access rights)
});
File.WriteAllBytes(@"d:\print.pdf", output.FileDetails.File);