vmprint  by cosmiciron

Precise document rendering engine for any environment

Created 5 months ago
653 stars

Top 50.3% on SourcePulse

GitHubView on GitHub
Project Summary

Summary

VMPrint addresses the challenges of rendering multi-page documents consistently across diverse JavaScript environments, from browsers to serverless functions. It offers a pure JavaScript, dependency-free solution that bypasses traditional web rendering pipelines (HTML/CSS, PDF.js, React-PDF) and heavy server-side tools like headless Chromium. This enables developers to achieve publication-grade document output with a small footprint, providing a predictable and inspectable layout engine for applications requiring reliable document generation.

How It Works

VMPrint employs a deterministic spatial simulation engine where document elements are treated as autonomous "actors" negotiating their geometry within bounded "arenas" (pages). Layout is achieved through a process of collision detection and constraint solving, aiming for a stable world state rather than relying on a DOM or browser layout engine. This actor-based, simulation-driven approach ensures identical output across all JavaScript runtimes and allows for deep inspection and instrumentation of the layout process.

Quick Start & Requirements

  • Prerequisites: Node.js 18+, npm 9+.
  • Installation: Clone the repository (git clone https://github.com/cosmiciron/vmprint.git), navigate into the directory (cd vmprint), and install dependencies (npm install).
  • Running: Render a JSON document to PDF via the CLI: npm run dev --prefix cli -- --input engine/tests/fixtures/regression/08-dropcap-pagination.json --output out.pdf.
  • Demos & Docs: Live demo available at https://cosmiciron.github.io/vmprint/examples/ast-to-canvas-webfonts/index.html. Static browser demos are located in docs/examples/.

Highlighted Details

  • Performance: Capable of rendering 325 pages (80,000 words) from Markdown to PDF in 2.32 seconds on a tablet. A warmed runtime achieves total layout and render times around 439ms.
  • Cross-Environment Consistency: Guarantees identical layout output across browser, Node.js, serverless (Cloudflare Workers, AWS Lambda), and edge runtimes.
  • Minimal Footprint: The browser bundle with standard fonts is approximately 85 KiB (Brotli-compressed), with core components around ~1.7MB unpacked. It requires no external runtime dependencies like PDF.js or React.
  • Runtime Scripting: Enables elements to react to document state (e.g., page count, headings) and dynamically modify content or replace themselves after initial layout settlement, facilitating complex document compositions.
  • Inspectable Layout: Designed for transparency, offering tools to name actors, measure boundaries, and trace output back to source elements, aiding debugging and understanding.

Maintenance & Community

The project is modular, with core components published as standalone npm packages and related tools like draft2final available separately. Specific community channels (e.g., Discord, Slack) are not detailed in the README.

Licensing & Compatibility

  • License: Apache 2.0.
  • Compatibility: The permissive Apache 2.0 license allows for commercial use and integration into closed-source projects. The engine's identical behavior across environments enhances compatibility.

Limitations & Caveats

The API is subject to evolution, although the core architectural principles are stable. The README indicates that "Scripting Series 1 is now complete," suggesting ongoing development and potential for future API changes in this area.

Health Check
Last Commit

2 months ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
0
Star History
0 stars in the last 30 days

Explore Similar Projects

Feedback? Help us improve.