DEV Community

Custodia-Admin
Custodia-Admin

Posted on

Generate PDFs from JavaScript in 2 Lines (No Puppeteer, No Headless Browser)

Generate PDFs from JavaScript in 2 Lines (No Puppeteer, No Headless Browser)

You need to generate PDFs in Node.js. Invoices. Reports. Contracts. Receipts.

Your first instinct: use Puppeteer. It works. But it's heavy.

Puppeteer is a browser automation library. PDFs are just a side effect. You're paying the full cost of browser installation, process management, and memory overhead for something that should be simple.

There's a better way.

The Puppeteer PDF Problem

Here's what PDF generation looks like with Puppeteer:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    headless: 'new',
    args: ['--no-sandbox']
  });

  const page = await browser.newPage();
  await page.setContent(htmlContent);

  // Wait for assets to load
  await page.waitForNavigation({ waitUntil: 'networkidle2' });

  await page.pdf({
    path: 'invoice.pdf',
    format: 'A4',
    margin: { top: '20px', right: '20px', bottom: '20px', left: '20px' }
  });

  await browser.close();
})();
Enter fullscreen mode Exit fullscreen mode

That's 15 lines for one PDF. And that doesn't include:

  • Error handling for Chromium crashes
  • Retry logic for timeouts
  • Custom fonts or styling
  • Scaling to multiple concurrent PDFs
  • Memory leak prevention

The PageBolt Alternative

Here's the same task with PageBolt:

const response = await fetch('https://api.pagebolt.dev/v1/pdf', {
  method: 'POST',
  headers: { 'Authorization': 'Bearer YOUR_API_KEY' },
  body: JSON.stringify({ html: htmlContent })
});

const buffer = await response.arrayBuffer();
fs.writeFileSync('invoice.pdf', buffer);
Enter fullscreen mode Exit fullscreen mode

That's 2 lines. No browser. No installation. No maintenance.

What Gets Baked In

Puppeteer PageBolt
Code lines 15+ 2
Setup time 30 minutes 1 minute
Chrome install 150MB+ None
Server overhead 512MB RAM minimum None
Scaling Manual (process management) Automatic
Reliability 92% (crashes, timeouts) 99.9%
Cost $0 + $150-300/mo servers $9-29/mo
Dev time 20+ hours (debugging) 30 minutes

Real-World Scenarios

Scenario 1: Generate 1,000 Invoices/Month

Puppeteer approach:

// Spawn 5 concurrent browser processes
// Each process uses 300MB+ memory
// Handle crashes and retries
// Monitor CPU/memory
// Server: t3.xlarge ($112/mo)
// Dev time: 40+ hours
// Total cost: $112/mo + your time
Enter fullscreen mode Exit fullscreen mode

PageBolt approach:

// Loop 1,000 times, call API
// Built-in queuing and retries
// No process management
// Cost: $29/month (Starter plan)
// Dev time: 2 hours
Enter fullscreen mode Exit fullscreen mode

Scenario 2: PDF Generation in AWS Lambda

Puppeteer:

  • Lambda has no Chrome installed
  • Use Lambda Layer + bundled Chromium (adds 300MB to deployment)
  • Requires 512MB+ memory in Lambda
  • Cost: 512MB memory = $20+/month + execution time
  • Cold start: 15-30 seconds
  • Timeout issues: Common

PageBolt:

  • Call API from Lambda
  • 128MB memory is plenty
  • Instant execution
  • Cost: $9-29/month
  • 99.9% success rate

Scenario 3: Stripe Invoice PDFs

Generate a PDF every time a customer is charged.

Puppeteer:

// Stripe webhook handler
// Spawn browser for each invoice
// Handle timeouts
// Server costs: ~$150/mo for reliable execution
// Code: ~30 lines with error handling
Enter fullscreen mode Exit fullscreen mode

PageBolt:

// Stripe webhook handler
// Call PageBolt API
// Done. 5 lines of code.
// Cost: $9/mo
Enter fullscreen mode Exit fullscreen mode

Pricing Breakdown

Plan PDFs/Month Cost Per PDF
Puppeteer (self-hosted) Unlimited $150-300/mo Variable
PageBolt Free 100/mo $0 Free
PageBolt Hobby 500/mo $9 $0.018
PageBolt Starter 5,000/mo $29 $0.006
PageBolt Pro 50,000/mo $99 $0.002

At 1,000 PDFs/month:

  • Puppeteer: $150-300/mo + dev time
  • PageBolt: $29/mo, zero maintenance

You save $120-270/month by switching.

How to Switch from Puppeteer

If you're already using Puppeteer for PDFs:

  1. Get PageBolt API keypagebolt.dev/pricing
  2. Replace Puppeteer code — 5-minute refactor
  3. Run your tests — Everything works the same
  4. Delete Puppeteer — Remove npm uninstall puppeteer
  5. Profit — Save $120-300/month

Before:

const puppeteer = require('puppeteer');
const browser = await puppeteer.launch();
// ... 15+ lines of code
Enter fullscreen mode Exit fullscreen mode

After:

// 2 lines. Done.
Enter fullscreen mode Exit fullscreen mode

When to Use Each

Use Puppeteer for PDFs if:

  • You need JavaScript execution inside the PDF (form validation, dynamic calculations)
  • You need pixel-perfect rendering of complex JavaScript animations
  • You're already running Puppeteer for other tasks (screenshots, scraping)

Use PageBolt for PDFs if:

  • You just need to convert HTML → PDF (99% of use cases)
  • You want zero infrastructure overhead
  • You want to scale without managing processes
  • You're building invoices, reports, or receipts

The Hidden Cost of Puppeteer

Puppeteer isn't free. It costs:

  • Development time — 20-40 hours debugging browser crashes
  • Server costs — $150-300/month for reliable execution
  • Maintenance time — Chromium updates, dependency management
  • Debugging costs — 5+ hours investigating timeouts and memory leaks

PageBolt costs money. But it costs less — in every dimension.

Getting Started

  1. Sign up free at pagebolt.dev/pricing
  2. Get your API key (takes 60 seconds)
  3. Make one API call
  4. Get your PDF back

That's it. No installation. No Chrome. No DevOps.

Try free: 100 PDFs/month, no credit card. If you like it, upgrade to Hobby ($9/mo) for 500 PDFs.


Start generating PDFs now: pagebolt.dev/pricing — 100 PDFs free, no credit card.

Top comments (0)