Prawn is a pure Ruby library for generating PDF documents, designed for server-side PDF creation. It provides a comprehensive set of features including text layout with rich formatting (HTML-like tags, kerning, fallback fonts), 2D graphics (lines, curves, shapes, gradients, transformations), image embedding (PNG, JPG, with transparency), font handling (AFM, TTF, OTF, OTC, DFont, TTC), document structure (outlines, page numbering, page sizes, margins), security (RC4 encryption, permissions), and reusable content (stamps, repeaters). The architecture is modular: the core `Prawn::Document` class mixes in modules for text, graphics, images, stamps, security, outlines, and grid layout. Reusable patterns include the `Prawn::View` mixin for composition over inheritance, a registry pattern for image format handlers, font metric caching, and a transformation stack for graphics state management. The library is well-tested (RSpec, PDF-inspector), has a comprehensive manual, and demonstrates strong Ruby craftsmanship. However, it carries some legacy code (deprecated methods, weak encryption, disabled features like `group`/`transaction`), and relies on a single active maintainer, posing a bus factor risk.
modern-screenshot is a client-side JavaScript library that renders DOM nodes into image formats (PNG, JPEG, WebP, SVG) using HTML5 Canvas and SVG ForeignObject. It clones a DOM subtree, captures computed styles (including pseudo-elements, scrollbars, CSS custom properties), embeds external resources (images, fonts, SVG symbols), and produces a bitmap or data URL. The architecture is modular: a recursive clone phase captures structure and styles, an embedding phase resolves and inlines external assets, and a rendering phase converts the cloned DOM to a Canvas via an intermediate SVG foreignObject. It supports Web Workers for parallel resource fetching, singleton context for repeated screenshots, DPI control via PNG/JFIF metadata injection, and comprehensive edge cases (shadow DOM, cross-origin iframes, @font-face with CSS layers, and Safari/Firefox quirks). The codebase is well-structured, thoroughly tested with Puppeteer-based image snapshot tests, and actively maintained.
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.