WeasyPrint is a production-grade Python library and CLI that renders HTML/CSS documents to PDF with high fidelity to print-focused web standards. In production it parses HTML via tinyhtml5, parses and validates CSS via tinycss2/cssselect2, builds a CSS box tree, runs full CSS layout algorithms for block, inline, table, flex, grid, multicolumn, floats, and paged media, then paints the result into a PDF via pydyf. It also renders embedded and standalone SVG, embeds and subsets fonts through Pango, HarfBuzz, Fontconfig, and fontTools, and supports PDF/A, PDF/UA, PDF/X, PDF forms, attachments, bookmarks, metadata, and e-invoice flavors such as Factur-X/ZUGFeRD. The main entry points are the `weasyprint` command-line tool (`weasyprint/__main__.py`) and the public Python API exposing `HTML`, `CSS`, `Document`, and `Page` (notably `HTML(...).write_pdf(...)`). Architecturally the repository is a layered pipeline rather than a monolith or microservice: CSS property validation and computed-value resolution feed a formatting-structure builder, which produces boxes; those boxes go through layout modules that handle pagination and page-breaking; a drawing layer converts the laid-out box tree into PDF stream operations; and the PDF package assembles final file objects, metadata, and conformance variants. The code is heavily specification-driven, with many docstring references to CSS 2.1, CSS Paged Media, CSS Flexbox/Grid, SVG, and PDF standards. Extensive pixel-comparison tests, regression tests tied to GitHub issues, and CI workflows for PDF/A and PDF/UA validation back the implementation. External runtime dependencies include pydyf, tinyhtml5, tinycss2, cssselect2, Pyphen, Pillow, fontTools, and native Pango/HarfBuzz/Fontconfig libraries; Ghostscript is used only by the test suite for rendering comparisons. The codebase is mature and generally well-structured, with clean separation between CSS processing, layout, drawing, and PDF output. It contains some inevitable complexity around pagination, table layout, and font handling, plus a set of `xfail` tests and TODO comments marking known spec coverage gaps, but overall it is one of the strongest open-source HTML-to-PDF engines and is actively maintained with recent security fixes and broad standards support.
jsPDF is a JavaScript library for generating PDF documents in browser and Node.js environments. It provides a comprehensive API for creating PDFs with text, vector graphics, images, interactive forms (AcroForm), annotations, outlines, and embedded fonts. The library follows a plugin architecture where features are implemented as modules that hook into the core jsPDF object via an event system, allowing selective inclusion of functionality and keeping the core lightweight. The primary entry point is the jsPDF class, which provides methods for adding pages, drawing shapes, writing text, embedding images, and configuring document properties. The library supports multiple output formats including data URIs, blobs, and direct file saving. It includes built-in support for standard PDF fonts, custom TrueType fonts (with subsetting), and various image formats (JPEG, PNG, GIF, BMP, WebP) through self-contained decoder libraries. Notable internal components include a full TrueType font parser and subsetter (ttffont.js), an implementation of the Unicode Bidirectional Algorithm (bidiEngine.js), a WebP image decoder ported from libwebp (WebPDecoder.js), and a JPEG encoder (JPEGEncoder.js). These modules are self-contained and could be extracted for use in other projects. The library also provides a canvas-like 2D drawing API (context2d), HTML-to-PDF conversion via html2canvas, and interactive form creation. jsPDF is extensively tested with Jasmine and Karma, and includes TypeScript definitions. It is distributed as ES modules, UMD, and Node.js builds. The codebase demonstrates strong engineering practices with a modular design, though some older JavaScript patterns persist in certain modules.
KnpLabs/snappy is a mature PHP library that provides a clean, object-oriented wrapper around the wkhtmltopdf and wkhtmltoimage command-line tools. It enables generation of PDF documents and image thumbnails from HTML content or URLs. The library is architected around an abstract base class (AbstractGenerator) that implements the template method pattern, handling command construction, process execution via Symfony Process, temporary file management, and PSR-3 logging. Concrete subclasses (Pdf and Image) define their own option sets and handle special cases like converting inline HTML strings to temporary files for header/footer content. The library is widely used in the PHP ecosystem, with dedicated Symfony and Laravel integration bundles. It requires PHP 8.1+ and depends only on symfony/process and psr/log, making it lightweight and easy to integrate.
mPDF is a mature PHP library that generates PDF documents from UTF-8 encoded HTML content. It is not a standalone application but a dependency used within PHP projects (e.g., Laravel, Symfony) via Composer. The library parses HTML and CSS, handles complex typography (including bidirectional text, Indic and Myanmar scripts, hyphenation), and produces PDF output with support for barcodes, watermarks, forms, table of contents, PDF/A compliance, and encryption. The architecture follows a service-oriented pattern: the central `Mpdf` class orchestrates a set of specialized services (CSS parser, color converter, size converter, image processor, tag handlers, writers) assembled by a `ServiceFactory`. HTML tags are mapped to handler classes in `src/Tag/` that extend `BlockTag`, `InlineTag`, or `SubstituteTag`. PDF output is built by writer classes in `src/Writer/` that write raw PDF objects via a `BaseWriter`. External dependencies include FPDI for PDF import, PSR-3 logging, PSR-7 HTTP messages, and the `myclabs/deep-copy` library for table of contents page numbering. The library is extensively tested with over 200 unit tests and snapshot tests that compare generated PDFs against stored references.
html2pdf.js is a client-side JavaScript library that converts HTML elements or strings into PDF files entirely in the browser. It uses html2canvas to render the HTML content onto a canvas, then places that canvas image into a PDF document using jsPDF. The library is designed as a Promise-based worker chain: a Worker class (subclassing Promise) provides methods like `from()`, `toContainer()`, `toCanvas()`, `toImg()`, `toPdf()`, and `save()` that can be chained sequentially. Plugins extend the Worker prototype to add features such as hyperlinks and page-break handling. The main entry point is the `html2pdf` function exported from `src/index.js`, which creates a Worker and optionally starts the conversion chain. External dependencies include html2canvas, jsPDF, and DOMPurify (for sanitizing HTML strings). The library is intended for browser use only and does not run in Node.js. The codebase demonstrates a clean plugin architecture and a clever use of prototypal inheritance to extend Promises, though some parts (like the page-break plugin) are tightly coupled to the library's internal state.
ChromiumHtmlToPdf is a .NET library and CLI tool that converts HTML to PDF (and PNG) using headless Google Chrome or Microsoft Edge via the Chrome DevTools Protocol (CDP). The core library (ChromiumHtmlToPdfLib) provides a managed C# API with synchronous and asynchronous methods for conversion, supporting extensive configuration of page settings, headers/footers, margins, paper size, JavaScript execution, and file caching. The console application (ChromiumHtmlToPdfConsole) wraps this library into a command-line tool with over 50 options, enabling batch conversions, multi-threading, and integration into scripts or CI/CD pipelines. The architecture is a two-project solution: a netstandard2.0/2.1 library and a .NET 8 console app packaged as a dotnet tool. Key entry points include the Converter class (ConvertToPdf/ConvertToImage methods) and the console's Program.cs. External dependencies are limited to a Chromium-based browser (Chrome/Edge) installed on the system, plus NuGet packages for JSON serialization, logging abstractions, and image processing (AngleSharp, Magick.NET). The codebase demonstrates solid engineering with reusable components like a file-backed cache, CDP protocol models, and pluggable loggers, but suffers from minor technical debt such as deprecated BinaryFormatter usage, disabled certificate validation in HTTP helpers, and version drift between projects. No automated tests exist, increasing regression risk for a process-heavy library.