FitToPage.js: Fit HTML Content to Single PDF Page
dev.toยท9hยท
Discuss: DEV
Preview
Report Post

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](https://โ€ฆ

Similar Posts

Loading similar posts...