Muonroi.Pdf.Abstractions 1.0.0-alpha.16

This is a prerelease version of Muonroi.Pdf.Abstractions.
dotnet add package Muonroi.Pdf.Abstractions --version 1.0.0-alpha.16
                    
NuGet\Install-Package Muonroi.Pdf.Abstractions -Version 1.0.0-alpha.16
                    
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="Muonroi.Pdf.Abstractions" Version="1.0.0-alpha.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Muonroi.Pdf.Abstractions" Version="1.0.0-alpha.16" />
                    
Directory.Packages.props
<PackageReference Include="Muonroi.Pdf.Abstractions" />
                    
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 Muonroi.Pdf.Abstractions --version 1.0.0-alpha.16
                    
#r "nuget: Muonroi.Pdf.Abstractions, 1.0.0-alpha.16"
                    
#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 Muonroi.Pdf.Abstractions@1.0.0-alpha.16
                    
#: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=Muonroi.Pdf.Abstractions&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Muonroi.Pdf.Abstractions&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Tool

Muonroi.Pdf.Abstractions

Contracts-only package for the Muonroi HTML/CSS-to-PDF pipeline — the shared interfaces, options, and exceptions that both the OSS engine and your application code depend on.

NuGet License: Apache 2.0

This package ships the stable contracts (IMPdfService, IMPdfRenderer<TModel>, IPdfCssPolicy, and the low-level adapter seams) that the rendering engine is built on. It carries no runtime rendering behavior — it exists so that application code, custom policies, and the source-generator companion can all depend on the same interface assembly without taking a transitive dependency on the full engine.

To actually render PDFs, depend on Muonroi.Pdf and call AddPdf(). Add Muonroi.Pdf.Governance for the built-in CSS policy implementations, or Muonroi.Pdf.Enterprise for the enterprise extensions.

Installation

dotnet add package Muonroi.Pdf.Abstractions --prerelease

Quick Start

This package is contracts-only — there is no AddXxx registration here. The typical usage pattern is:

1. Consume IMPdfService (registered by Muonroi.Pdf)

using Muonroi.Pdf.Abstractions;

// IMPdfService is registered by Muonroi.Pdf's AddPdf() extension.
// Inject it wherever you need to render HTML to PDF.
public class ReportService(IMPdfService pdf)
{
    public async Task<byte[]> GenerateAsync(string html, CancellationToken ct = default)
    {
        var (bytes, result) = await pdf.RenderToBytesAsync(
            html,
            new PdfRenderOptions(),
            ct);

        Console.WriteLine($"Pages: {result.PageCount}  Bytes: {result.ByteCount}");
        return bytes;
    }
}

2. Stream directly to a file (recommended for production — avoids buffering)

await using FileStream output = File.Create("report.pdf");
PdfRenderResult result = await pdf.RenderAsync(html, output, new PdfRenderOptions());

3. Implement a custom CSS policy

using Muonroi.Pdf.Abstractions.Policy;

public sealed class MyPolicy : IPdfCssPolicy
{
    public string Id => "my-policy-v1";
    public PdfPolicyLimits Limits => new();

    public ValueTask<PolicyValidationResult> ValidateAsync(
        IPdfDocumentContext context,
        CancellationToken cancellationToken = default)
    {
        // Inspect context.ElementCount, context.MaxDepth, etc.
        // Return PolicyValidationResult.Accept() or PolicyValidationResult.Reject(violations).
        return ValueTask.FromResult(PolicyValidationResult.Accept());
    }
}

See Muonroi.Pdf.Samples for a full working host using AddPdf() and all rendering scenarios.

Features

  • IMPdfService — primary rendering contract: stream-out RenderAsync, multi-page RenderMultiPageAsync, and buffer RenderToBytesAsync
  • IMPdfRenderer<TModel> / IMPdfRendererFactory — strongly-typed per-template renderer seam; populated at compile time by Muonroi.Pdf.SourceGenerators
  • IPdfCssPolicy / IPdfDocumentContext — extensible CSS policy gate: implement to enforce custom HTML/CSS subset rules before layout begins
  • IFontResolver — bytes-only font resolution contract (path-traversal-safe); implement for custom font stores
  • IResourceResolver — resolves external resources (images, stylesheets) during rendering
  • PdfConfigsIConfiguration-bound options class covering input limits, font resolver, and policy tunables; bound from the "PdfConfigs" section
  • PdfTemplateAttribute — compile-time marker for source-generator–driven renderer emission
  • Engine adapter seamsIHtmlParser, ICssCascadeEngine, IPdfWriter, IImageDecoder, and related interfaces for swapping engine internals
  • Structured exception hierarchyPdfException (base), PdfFormatException, PdfPolicyException, PdfSecurityException, PdfInputLimitException
  • Targets netstandard2.0; polyfills ReadOnlyMemory<T> and ValueTask<T> for broad host compatibility

Configuration

PdfConfigs is the single IConfiguration-bound options class. Bind it via the implementation package's AddPdf() call — no direct binding is needed here.

appsettings.json shape:

{
  "PdfConfigs": {
    "RequirePolicySignature": false,
    "Limits": {
      "MaxHtmlBytes": 8388608,
      "MaxDomDepth": 256,
      "MaxElementCount": 100000,
      "MaxImagePixels": 25000000,
      "MaxPages": 1000,
      "MaxRenderDurationMs": 15000,
      "MaxFontFiles": 32
    },
    "FontResolver": {
      "FallbackToFirstRegistered": true,
      "GenericFamilyMap": {
        "sans-serif": "Arial",
        "serif": "Times New Roman",
        "monospace": "Courier New"
      },
      "Fonts": [
        { "Family": "Arial", "Path": "fonts/arial.ttf", "Weight": 400, "Style": "Normal" }
      ]
    },
    "Policy": {
      "SoftDegradeUnknownDisplay": false,
      "AllowModernLayout": false
    }
  }
}

AllowModernLayout: true enables real CSS Flexbox and CSS Grid layout engines (opt-in, default off). SoftDegradeUnknownDisplay: true downgrades unsupported display values to block instead of aborting with PdfPolicyException.

API Reference

Type Purpose
IMPdfService Primary rendering service: RenderAsync, RenderMultiPageAsync, RenderToBytesAsync
IMPdfRenderer<TModel> Strongly-typed template renderer; TemplateId + RenderAsync(model, stream, options, ct)
IMPdfRendererFactory Resolves renderers by template id: Get<TModel>, TryGet<TModel>
IPdfCssPolicy CSS policy gate: Id, Limits, ValidateAsync(documentContext, ct)
IPdfDocumentContext Opaque document context passed to policies: ElementCount, MaxDepth, TotalStylesheetBytes, SourceHtmlBytes
IFontResolver Font bytes resolution: ResolveAsync(FontRequest, ct)
IResourceResolver External resource resolution during rendering
IHtmlParser HTML parsing adapter seam
ICssCascadeEngine CSS cascade adapter seam
IPdfWriter Low-level PDF byte-writing adapter seam
IImageDecoder Image decoding adapter seam
PdfConfigs IConfiguration-bound options; section name "PdfConfigs"
PdfConfigs.PdfLimits Input and rendering resource limits
PdfFontResolverConfig Font registration list and generic-family map
PdfPolicySettings Policy tunables: AllowModernLayout, SoftDegradeUnknownDisplay
PdfTemplateAttribute Compile-time attribute for source-generator renderer emission
FontRequest Font selection record: Family, Weight, Style
FontWeight Enum: Thin(100) through Black(900)
FontStyle Enum: Normal, Italic, Oblique
PdfException Base exception: RuleId, Detail
PdfFormatException Malformed HTML/CSS input
PdfPolicyException CSS policy gate rejection (carries IReadOnlyList<PolicyViolation>)
PdfSecurityException Security rule violation
PdfInputLimitException Input exceeded a configured PdfLimits threshold

Samples

  • Muonroi.Pdf.Samples — full Generic Host wiring with AddPdf(), all rendering scenarios (minimal, invoice, header/footer, watermark, Flexbox, CSS Grid, multi-page, policy rejection)
  • Muonroi.Pdf.AotSample — AOT-compatible setup with a pre-registered IFontResolver

Compatibility

  • Target framework: netstandard2.0
  • License: Apache-2.0 (OSS)

License

Apache-2.0. See LICENSE-APACHE in the repository root.

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.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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 (3)

Showing the top 3 NuGet packages that depend on Muonroi.Pdf.Abstractions:

Package Downloads
Muonroi.BuildingBlock.All

Metapackage for Muonroi Building Block - Includes all sub-packages for a complete infrastructure setup.

Muonroi.Pdf

HTML/CSS to PDF layout engine: box-tree construction, pagination, and rendering coordination for Muonroi applications.

Muonroi.Pdf.Governance

CSS policy enforcement and HTML/CSS parsing adapters for Muonroi PDF rendering.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-alpha.16 31 6/22/2026
1.0.0-alpha.15 92 5/31/2026