Rmp.DocProc.HtmlToPdf 1.0.0

dotnet add package Rmp.DocProc.HtmlToPdf --version 1.0.0
                    
NuGet\Install-Package Rmp.DocProc.HtmlToPdf -Version 1.0.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="Rmp.DocProc.HtmlToPdf" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rmp.DocProc.HtmlToPdf" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Rmp.DocProc.HtmlToPdf" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Rmp.DocProc.HtmlToPdf --version 1.0.0
                    
#r "nuget: Rmp.DocProc.HtmlToPdf, 1.0.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.
#:package Rmp.DocProc.HtmlToPdf@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Rmp.DocProc.HtmlToPdf&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Rmp.DocProc.HtmlToPdf&version=1.0.0
                    
Install as a Cake Tool

Rmp.DocProc.HtmlToPdf

Async-friendly document formatting package, designed for queued jobs.

Current capability

  • HTML file to PDF file conversion using Playwright Chromium.
  • HTML file to PNG file conversion (scaffold for additional output formats).
  • Optional relative URL normalization to absolute URLs with a provided base URL.

Install

dotnet add package Rmp.DocProc.HtmlToPdf

Browser provisioning (no manual install required by default)

The package tries to auto-install a Playwright browser at runtime if Chromium is missing.

  • Default behavior: first run downloads Chromium automatically.
  • Good for worker services where you want install-free onboarding.
  • Requires network access on first run.

You can still preinstall manually if preferred:

pwsh bin/Debug/net8.0/playwright.ps1 install chromium

or for published artifacts:

pwsh playwright.ps1 install chromium

Important limitation:

  • NuGet cannot practically bundle all OS-specific browser binaries inside a single package without major size and distribution drawbacks.
  • The closest "bundled" experience is auto-provisioning on first run, or reusing an already installed browser executable/channel.

Usage (queued worker)

using Rmp.DocProc.HtmlToPdf.Abstractions;
using Rmp.DocProc.HtmlToPdf.Html;
using Rmp.DocProc.HtmlToPdf.Pipeline;

var handler = new HtmlToPdfConversionHandler(new HtmlToPdfOptions
{
    BaseUrl = "https://example.com",
    NormalizeRelativeUrls = true,
    PrintBackground = true,
    AutoInstallBrowser = true
});

var dispatcher = new ConversionDispatcher(new[] { handler });

var job = new ConversionJob(
    SourcePath: "C:/queue/input/123.html",
    DestinationPath: "C:/queue/output/123.pdf",
    InputFormat: DocumentFormat.Html,
    OutputFormat: DocumentFormat.Pdf,
    Metadata: new Dictionary<string, string>
    {
        ["jobId"] = "123"
    });

await dispatcher.DispatchAsync(job);

Use system Chrome or Edge instead of Playwright-managed Chromium

If your environment already has a managed browser installation, point the handler to it:

var handler = new HtmlToPdfConversionHandler(new HtmlToPdfOptions
{
    AutoInstallBrowser = false,
    BrowserChannel = "msedge"
    // or BrowserExecutablePath = "C:/Program Files/Google/Chrome/Application/chrome.exe"
});

Usage with DI and background worker

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Rmp.DocProc.HtmlToPdf.DependencyInjection;
using Rmp.DocProc.HtmlToPdf.Html;

var host = Host.CreateDefaultBuilder(args)
    .ConfigureServices(services =>
    {
        services
            .AddRubiconDocProcHtmlToPdf(
                pdfOptions: new HtmlToPdfOptions
                {
                    BaseUrl = "https://example.com/assets/",
                    NormalizeRelativeUrls = true
                },
                imageOptions: new HtmlToImageOptions
                {
                    Width = 1280,
                    Height = 1810
                })
            .AddRubiconDocProcBackgroundWorker(queueCapacity: 500);
    })
    .Build();

await host.RunAsync();

Queue producer code can enqueue ConversionJob values through IConversionJobQueue.

Strict enterprise mode (no runtime downloads)

Use strict mode when hosts are locked down and browser binaries must be provisioned by ops.

using Rmp.DocProc.HtmlToPdf.DependencyInjection;

services
    .AddRubiconDocProcHtmlToPdfEnterprise(
        pdfOptions: new HtmlToPdfOptions
        {
            BrowserChannel = "msedge"
        },
        imageOptions: new HtmlToImageOptions
        {
            BrowserChannel = "msedge"
        },
        preflightBrowserOnStartup: true)
    .AddRubiconDocProcBackgroundWorker();

What strict mode does:

  • Forces AutoInstallBrowser = false for registered handlers.
  • Optionally preflights browser launch at host startup.
  • Throws a clear error if no runnable browser is available.

Relative URL handling

When BaseUrl is set and NormalizeRelativeUrls is true:

  • <base href="..."> is injected/updated in <head>.
  • relative values in src, href, poster, data, and srcset are rewritten to absolute URLs.

This supports the flow where a pre-rendered HTML file is queued and converted later.

Pre-queue normalization

If your producer service needs to rewrite relative URLs before the HTML is saved and queued, call HtmlUrlNormalizer.NormalizeAsync(...) directly and persist the returned HTML.

using Rmp.DocProc.HtmlToPdf.Html;

var normalizedHtml = await HtmlUrlNormalizer.NormalizeAsync(rawHtml, "https://example.com/base/");
await File.WriteAllTextAsync("C:/queue/input/123.html", normalizedHtml);
Product Compatible and additional computed target framework versions.
.NET 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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.0.0 0 5/20/2026