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

@benpley/wappler-html2pdf

v2.0.0

Published

Convert HTML to PDF using Playwright Chromium in Wappler Server Connect

Downloads

325

Readme

HTML to PDF — Wappler Server Connect Module

Version Playwright Wappler License: MIT

This Wappler Server Connect module converts HTML content into PDF files using Playwright Chromium.
It is ideal for generating invoices, reports, onboarding documents, certificates, or any printable HTML content.


Features

  • Convert any HTML string into a PDF file
  • Fully server‑side rendering using Playwright Chromium
  • Supports:
    • Page formats (A4, Letter, Legal, etc.)
    • Margins and scaling
    • Landscape or portrait orientation
    • Background graphics
    • Header and footer HTML templates
    • CSS @page support (via preferCSSPageSize)
  • Advanced rendering controls:
    • Wait for a selector before generating
    • Optional delay for dynamic content
  • Save PDFs to a custom path or temporary folder
  • Works seamlessly inside Wappler NodeJS projects

🚨 Important: Playwright Browser Install

Playwright does not bundle its browser binaries the same way Puppeteer does. After installing dependencies, the Chromium browser used for rendering must be downloaded:

npx playwright install --with-deps chromium

A postinstall script running this command is included in package.json, but on some hosts (locked-down CI, limited permissions) you may need to run it manually.


Installation

Install Wappler HTML to PDF using Wappler's built-in Extension Manager:

  1. Open Wappler and go to Extensions → Extension Manager.
  2. Search for wappler-html2pdf or browse the Widgets category.
  3. Click Install next to Wappler HTML to PDF by Ben Pleysier.
  4. Restart Wappler (or reload your project) when prompted.
  5. Ensure the Playwright Chromium browser is installed (see above), otherwise PDF generation will fail with a "browser executable not found" error.

Quick Example

Add the HTML to PDF action to a Server Connect action file with options like:

{
  "html": "<h1>Invoice #{{$_GET.id}}</h1><p>Thank you for your purchase, {{$_GET.name}}!</p>",
  "filename": "invoice_{{$_GET.id}}.pdf",
  "path": "uploads/invoices/invoice_{{$_GET.id}}.pdf",
  "format": "A4",
  "landscape": false,
  "printBackground": true,
  "marginTop": "10mm",
  "marginBottom": "10mm"
}

The action returns:

{
  "path": "/uploads/invoices/invoice_123.pdf",
  "filename": "invoice_123.pdf",
  "size": 24531
}

You can then use sc_action.data.path (or the step's output name) on the client to show a download link, e.g. <a dmx-bind:href="sc_action.data.path" target="_blank">Download PDF</a>.


Configuration Options

HTML Content

  • html (required) — The HTML string to convert into PDF.

PDF Output

  • filename — Output filename (default: document.pdf)
  • path — Optional save path (e.g., uploads/pdfs/report.pdf)

Page Settings

  • formatA4, A3, A5, Letter, Legal, Tabloid
  • landscapetrue or false
  • printBackground — Print background graphics (default: true)
  • scale — Rendering scale (0.1 to 2, default: 1)

Margins

  • marginTop, marginRight, marginBottom, marginLeft
    Accepts units like mm, cm, or in.

Header & Footer

  • displayHeaderFooter — Enable header/footer rendering
  • headerTemplate — HTML template for header
  • footerTemplate — HTML template for footer
    (Playwright requires full HTML fragments: <html><body>...</body></html>)

Advanced

  • preferCSSPageSize — Use CSS-defined page size if present
  • waitForSelector — Wait for a specific element before generating
  • waitTime — Additional delay (ms) before PDF generation

All properties support static values or Wappler server data bindings.


Dependency

This module uses Playwright (Chromium engine).


Troubleshooting

"browser executable not found" / "Executable doesn't exist"

Playwright's Chromium binary is not installed. Run:

npx playwright install --with-deps chromium

See Playwright Browser Install above.

PDF is generated but blank / missing content

  • The HTML is likely rendered before dynamic content (JS/images/fonts) finishes loading.
  • Use waitForSelector to wait for a specific element that indicates the content is ready.
  • Or use waitTime to add a fixed delay (in milliseconds) before the PDF is captured.

Background colors/images are missing

  • Ensure printBackground is set to true (default).
  • Some CSS backgrounds also require -webkit-print-color-adjust: exact; in your stylesheet.

Header/footer not showing

  • Make sure displayHeaderFooter is enabled.
  • headerTemplate/footerTemplate must be full HTML fragments (e.g. <div style="font-size:10px;">...</div>), not just text.

Error: "Failed to generate PDF: ..." on shared hosting / containers

  • Chromium sandboxing can fail in restricted environments (Docker, some CI/CD, low-privilege containers).
  • The module already launches with --no-sandbox --disable-setuid-sandbox --disable-dev-shm-usage --disable-gpu, but you may also need to install missing system dependencies with npx playwright install-deps (Linux).

Custom path not saving where expected

  • Custom paths are relative to the project root, not /public. Directories are created automatically if missing.

Issues and Support

For bug reports, feature requests, or assistance, please use the Wappler Community Forum.

If this module saves you time or makes your Wappler workflow easier, you can support me at Buy Me A Coffee


Version 2.0.0 — now powered by Playwright (migrated from Puppeteer). Feedback welcome!