Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Generate PDFs using Puppeteer, Playwright, react-pdf/renderer, pdfkit, jsPDF — server-side document rendering, invoices, reports, and export workflows
layer
domain
category
backend
triggers
["generate pdf","pdf generation","export to pdf","invoice pdf","report pdf","puppeteer pdf","react-pdf","pdfkit","jspdf","server-side pdf","print to pdf"]
inputs
["Document type (invoice, report, certificate, contract)","Data source and template requirements","Styling complexity (simple text vs rich layouts)","Runtime environment (server-only, edge, client-side)","Volume expectations (on-demand vs batch)"]
outputs
["PDF generation implementation with chosen library","Document template system","API endpoint for on-demand PDF generation","Batch generation pipeline (if needed)","Download/email delivery integration"]
PDF generation is essential for invoices, reports, certificates, contracts, and data exports. This skill covers the full spectrum: from browser-based HTML-to-PDF rendering (Puppeteer/Playwright) to programmatic PDF construction (pdfkit, react-pdf) to client-side generation (jsPDF).
When to Use What
Library
Best For
Runtime
Styling
Size Impact
Puppeteer / Playwright
Complex HTML layouts, pixel-perfect CSS
Server (needs Chromium)
Full CSS, Tailwind, Flexbox, Grid
~400MB (Chromium)
@react-pdf/renderer
React developers, component-based layouts
Server or client
React-PDF subset (Flexbox, no CSS Grid)
~2MB
pdfkit
Programmatic PDF, precise control
Server (Node.js)
Manual positioning, no CSS
~5MB
jsPDF
Client-side generation, simple documents
Browser
Manual positioning
~300KB
Playwright page.pdf()
Already using Playwright, need PDF export
Server
Full CSS
~400MB
Decision shortcut:
Have complex HTML/CSS templates? Puppeteer or Playwright
Reuse browser instances with Puppeteer/Playwright -- launching Chromium per request is expensive (500ms+ cold start).
Use waitUntil: 'networkidle0' and document.fonts.ready to ensure all assets and fonts load before PDF capture.
Set explicit page size and margins -- defaults vary between libraries and can cause truncated content.
Use CSS @media print rules for Puppeteer/Playwright to hide UI chrome, adjust colors, avoid page-break issues.
Add page-break-inside: avoid on table rows and card elements to prevent splitting across pages.
Stream large PDFs instead of buffering the entire document in memory.
Queue batch PDF generation -- generating 100+ PDFs synchronously will timeout or OOM. Use a job queue.
Cache generated PDFs if the source data hasn't changed (hash the input, store in S3/R2).
Set Content-Disposition: attachment for downloads, inline for browser preview.
Test with real data -- long text, special characters, empty fields, and multi-page documents all break layouts.
Common Pitfalls
Pitfall
Impact
Fix
Launching new browser per request
500ms+ overhead, memory leaks
Reuse browser instance, pool pages
Missing fonts in container
Squares or fallback glyphs in PDF
Install fonts in Dockerfile, or embed base64 fonts
Not waiting for fonts/images
Missing content in PDF
waitUntil: 'networkidle0' + document.fonts.ready
Chromium in Docker without --no-sandbox
Crashes on startup
Add sandbox flags, use @sparticuz/chromium for Lambda
Content overflows page
Truncated text, overlapping elements
Test with long data, use page-break-inside: avoid
Blocking the main thread
Request timeouts on batch generation
Use background job queue (BullMQ, SQS)
Generating same PDF repeatedly
Wasted compute, slow UX
Cache by content hash, serve from CDN/S3
Docker Setup for Puppeteer
FROM node:20-slim
# Install Chromium dependencies
RUN apt-get update && apt-get install -y \
chromium \
fonts-liberation \
fonts-noto-color-emoji \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
# Tell Puppeteer to use installed Chromium
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
CMD ["node", "dist/server.js"]
Examples
Example 1: SaaS Invoice Generation
Library: @react-pdf/renderer (component-based, no Chromium needed)
Trigger: After successful payment via Stripe webhook
Flow: Stripe webhook → generate PDF → store in S3 → email to customer
Caching: Store in S3 keyed by invoice ID, serve directly on re-download
Example 2: Analytics Report Export
Library: Puppeteer (complex charts, CSS Grid layout)
Trigger: User clicks "Export as PDF" on dashboard
Flow: Render HTML template with Chart.js → Puppeteer PDF → stream to client
Optimization: Reuse browser instance, pool of 3 pages for concurrency
Example 3: Certificate / Diploma Generation
Library: pdfkit (precise positioning, custom fonts, background image)
Trigger: Course completion event
Flow: Event → queue job → pdfkit renders certificate → S3 → email
Batch: Use BullMQ for processing 500+ certificates after a cohort graduates