Skip to content

Latest commit

 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HtmlPdfNative

HTML & CSS → PDF for .NET, powered by its own native rendering engine

No headless browser. No Chromium. No WebView. No native dependencies.

HtmlPdfNative is a pure‑managed .NET port of the Rust [pdfmaker](https://pdfmaker.ink/web/) engine. It parses HTML, computes the CSS cascade, lays out the page, and draws every glyph, gradient, and shape itself — so it's small, deterministic, fully self‑contained, and produces identical output everywhere .NET runs.

Multi‑targets netstandard2.0 · net6.0 · net8.0 → runs on .NET Framework 4.6.1+, .NET Core/5+, Mono, Unity, Xamarin, and modern .NET.


✨ Why HtmlPdfNative

Most HTML‑to‑PDF libraries for .NET shell out to a headless browser (Chromium, Puppeteer, wkhtmltopdf) or wrap a native binary. HtmlPdfNative is different — it's a real, standalone rendering engine written entirely in C#:

  • 🧩 Own engine, pure managed — no browser, no Node.js, no unmanaged runtime to deploy.
  • Fast & lightweight — a single DLL; deterministic, pixel‑consistent output.
  • 🌍 Runs everywhere .NET does — server, desktop, container, or wherever netstandard2.0 is supported.
  • 🔒 100% offline — your documents never leave the process.

🖼 Showcase

Documents rendered entirely by HtmlPdfNative — straight from HTML/CSS, no browser involved. Sources live in [pdfmaker](https://pdfmaker.ink/web/).

Example16
Analytics Dashboard
Dark mode · gradients · KPI cards
Example9
Professional Invoice
Clean tables · business layout
Example25
Creative Vision
Bold type · vivid gradients
Example28
Annual Performance Report
Charts · tables · corporate style
Example18
Arabic (RTL)
Right‑to‑left shaping & bidi
Example17
Chinese (CJK)
Embedded CJK fonts

The screenshots above are the exact PDFs HtmlPdfNative produces from those .html sources.

🧩 Features

Category What's supported
Layout Block / inline / inline‑block, Flexbox, CSS Grid, multi‑column, position (relative/absolute/fixed), float, overflow clipping
Typography Web‑safe + @font-face web fonts, font-weight/style/stretch/variant, letter/word‑spacing, text-align: justify, text-shadow, text-decoration, drop caps (::first-letter), unitless & explicit line-height
Color & Backgrounds Named/hex/rgb()/rgba(), linear / radial / conic / repeating gradients, multi‑layer backgrounds, background-clip: text (gradient text)
Borders & Effects border-radius (incl. non‑uniform borders), per‑side borders, box-shadow (soft blur), opacity, mix-blend-mode, clip-path, filter (blur, grayscale, sepia…), backdrop-filter
Transforms translate, rotate, scale, skew, matrix, 3D transforms, transform-origin
Tables border-collapse, border-spacing, colspan/rowspan, striped rows, section (thead/tbody) colour & gradient backgrounds, rounded clipping, repeating headers
Lists & Content Many list-style-types, CSS counters & generated content (::before/::after)
Graphics Inline SVG (paths, gradients, shapes), raster images (PNG/JPEG/GIF/BMP/WebP), full‑color emoji
Internationalization CJK (中文 · 日本語 · 한국어), Arabic / Hebrew (RTL) with shaping & bidi, Cyrillic, vertical writing-mode
Paged media @page sizes (A4, Letter, custom…), margins, automatic & forced page breaks, @media print
PDF features Embedded subsetted fonts, clickable link annotations, password encryption

🚀 Quick start

Library

using HtmlPdfNative;

// From strings → PDF bytes
byte[] pdf = HtmlToPdf.Convert(
    "<h1 style='color:#6366f1'>Hello, PDF</h1>",
    css: "h1 { font-family: Arial; }",
    new ConversionOptions { Paper = PaperSize.A4 });
File.WriteAllBytes("hello.pdf", pdf);

// From files → PDF file
HtmlToPdf.ConvertFile("invoice.html", "styles.css", "invoice.pdf",
    new ConversionOptions { Paper = PaperSize.Letter });

ConversionOptions: Paper (A3 · A4 · A5 · Letter · Legal), explicit Width/Height (pt), and UserPassword/OwnerPassword for AES encryption.

Command‑line (htmlpdf test CLI)

dotnet run --project tests/HtmlPdfNative.Cli -- -i page.html -c style.css -o page.pdf -s a4
-i, --input <FILE>          Input HTML or Markdown file (required)
-c, --css <FILE>            Optional external CSS file
-o, --output <FILE>         Output PDF file (default: output.pdf)
-s, --paper-size <SIZE>     a3 | a4 | a5 | letter | legal (default: a4)
    --width / --height <PT>  Explicit page size in points
-e, --encrypt <PASSWORD>    AES-encrypt the output

🔨 Build

cd dotnet
dotnet build HtmlPdfNative.sln -c Release

The software rasterizer (used by filter: blur() / backdrop-filter) is on by default via SkiaSharp. Turn it off for a minimal, fully pure‑managed build:

dotnet build -c Release -p:HtmlPdfUseExternalPackages=false

Ship a self‑contained DLL with the fonts embedded (mirrors the Rust binary — one file, no Assets/ folder):

dotnet build -c Release -p:HtmlPdfEmbedAssets=true

📦 Project structure

Two projects — one library, one CLI:

Project Purpose
src/HtmlPdfNative The engine — the whole HTML → cascade → layout → paint → PDF pipeline in a single assembly. Vendor/ holds the ports of crates .NET lacks (PdfWriter, TtfParser, Subsetter, UnicodeBidi, Hyphenation, Shaping, SvgRender, EmojiColr, VariableFonts, Compression).
tests/HtmlPdfNative.Cli The htmlpdf test CLI (net8.0) that renders any .html/.md to PDF.

Shared build settings (multi‑targeting, netstandard2.0 polyfills) live in Directory.Build.props.

📎 Dependencies

Pure‑managed by default: AngleSharp (HTML parse/DOM), Markdig (Markdown), SixLabors.ImageSharp (raster decode). The optional native‑backed rasterizer adds SkiaSharp (for filter/backdrop-filter).

🔗 About

HtmlPdfNative is the .NET port of [PDFMaker](https://github.com/sorainnosia/PDFMaker/README.md (Rust). See the parent project for the website, the browser (WASM) app, and the Windows/Android downloads.

HTML to beautiful PDF, in managed .NET — anywhere.

About

Html CSS to PDF Native

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages