DEV Community

Cover image for FitToPage.js: Fit HTML Content to Single PDF Page
jQueryScript
jQueryScript

Posted on

FitToPage.js: Fit HTML Content to Single PDF Page

FitToPage.js: A 2KB JavaScript library that auto-fits HTML content to a single PDF page when you hit print.

Key features:

πŸ“ Measures rendered content automatically

🎯 Injects custom page size through CSS

πŸ–¨οΈ Works with native Cmd+P browser print

πŸ“ Preserves searchable text in output

βš™οΈ Configurable margins, padding, orientation

πŸ”„ Remeasure method for dynamic content

πŸͺΆ Zero dependencies, pure vanilla JS

Install via npm or CDN, call FitToPage.init(), and your print output fits perfectly on one page. Great for reports, dashboards, invoices, or any layout that needs clean single-page PDF export.

Check it out if you need reliable print-to-PDF without heavyweight libraries or server rendering.

πŸ‘‰ Blog Post

πŸ‘‰ GitHub Repo

πŸ‘‰ Live Demo

Top comments (0)