npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hyperdrive.bot/html-to-pdf

v0.1.0

Published

Smart HTML-to-PDF converter with intelligent height detection for single-page output

Readme

DevSquad HTML-to-PDF Converter

Smart HTML-to-PDF converter that automatically chooses the best method based on content height to ensure single-page output with optimal quality.

🚀 Features

  • Intelligent Height Detection: Measures content height and chooses optimal conversion method
  • Direct PDF Method: For normal-sized content (≤200 inches tall) with selectable text
  • PNG-to-PDF Method: For very long content that exceeds PDF height limits
  • Responsive Design Handling: Properly handles responsive CSS and web fonts
  • Lazy Loading Support: Automatically scrolls to trigger lazy-loaded content
  • CLI Interface: Easy command-line usage with various options
  • Production Ready: Used for client proposals and professional documents

📦 Installation

cd packages/cli/html-to-pdf
npm install

🔧 Usage

Basic Usage

# Convert HTML to PDF
node index.js input.html output.pdf

# With verbose logging
node index.js proposal.html proposal.pdf --verbose

# Custom browser width for responsive layouts
node index.js document.html output.pdf --width=1920

Advanced Examples

# Mobile responsive view
node index.js responsive.html mobile.pdf --width=375

# Tablet view
node index.js responsive.html tablet.pdf --width=768

# Desktop high-res view
node index.js report.html desktop.pdf --width=1920 --verbose

# Convert from URL
node index.js https://example.com/proposal.html remote.pdf

NPM Scripts

# Show help
npm run test:help

# Development mode (with verbose logging)
npm run dev input.html output.pdf

🧠 How It Works

  1. Page Loading: Loads HTML with proper viewport and font loading
  2. Lazy Content Trigger: Scrolls through page to trigger any lazy-loaded content
  3. Height Measurement: Measures total content height accurately
  4. Method Selection:
    • Height ≤ 19,200px (~200 inches): Direct PDF generation (preserves text selection)
    • Height > 19,200px: PNG-to-PDF method (ensures single-page output)
  5. PDF Generation: Creates single-page PDF with chosen method

📊 Performance

Typical conversion times:

  • Small documents (1-5 pages): 3-8 seconds
  • Medium proposals (5-15 pages): 8-15 seconds
  • Large reports (15+ pages): 15-30 seconds

Output quality:

  • Direct PDF: Selectable text, vector graphics, small file sizes
  • PNG-to-PDF: Pixel-perfect rendering, larger file sizes

⚙️ Configuration Options

node index.js <input.html> <output.pdf> [options]

Arguments

  • input.html - Path to HTML file or URL (required)
  • output.pdf - Output PDF path (required)

Options

  • --width=<pixels> - Browser width (default: 1366, range: 300-4000)
  • --verbose - Show detailed conversion logs
  • --help, -h - Show help information

💡 Use Cases

Client Proposals

node index.js proposal.html client-proposal.pdf --width=1366

Financial Reports

node index.js financial-report.html quarterly-report.pdf --verbose

Technical Documentation

node index.js api-docs.html documentation.pdf --width=1200

Marketing Materials

node index.js landing-page.html brochure.pdf --width=1920

🔍 Troubleshooting

Common Issues

"Input file not found"

  • Verify the HTML file path exists
  • Use absolute paths if needed

"Conversion failed: Timeout"

  • Increase system resources
  • Check for heavy external resources in HTML
  • Use --verbose to see where it fails

"Width must be between 300 and 4000"

  • Use reasonable browser widths
  • Common values: 375 (mobile), 768 (tablet), 1366 (laptop), 1920 (desktop)

Performance Tips

  • Self-host fonts instead of using CDN fonts for faster loading
  • Optimize images in HTML before conversion
  • Remove unnecessary scripts that don't affect visual output
  • Use local assets when possible to avoid network delays

🎯 Best Practices

HTML Optimization

<!-- ✅ Good: Self-hosted fonts -->
<link rel="stylesheet" href="./fonts/custom-font.css">

<!-- ✅ Good: Optimized images -->
<img src="./images/logo-optimized.png" alt="Logo">

<!-- ❌ Avoid: Heavy external resources -->
<script src="https://heavy-analytics.com/tracker.js"></script>

CSS for PDF

/* ✅ Good: Print-specific styles */
@media print {
  body { -webkit-print-color-adjust: exact; }
  .no-print { display: none; }
}

/* ✅ Good: Fixed dimensions */
.container { max-width: 1200px; margin: 0 auto; }

📈 Success Stories

Client Proposals: Generated professional PDFs for 50+ client proposals ✅ Financial Reports: Converted complex multi-section reports seamlessly
Marketing Materials: Created pixel-perfect brochures from responsive designs ✅ Technical Documentation: Handled long-form documentation with embedded media

🔗 Integration

With Build Systems

# Add to package.json scripts
"scripts": {
  "build:pdf": "node ../cli/html-to-pdf/index.js dist/index.html output.pdf"
}

With CI/CD

- name: Generate PDF
  run: |
    cd packages/cli/html-to-pdf
    npm install
    node index.js ../../web/dist/proposal.html ../../../artifacts/proposal.pdf

DevSquad CLI Tools | Part of the DevSquad development ecosystem