explaingit

alvarcarto/url-to-pdf-api

7,107HTMLAudience · developerComplexity · 3/5Setup · moderate

TLDR

API service that converts any URL or raw HTML into a PDF or screenshot image using headless Chrome, send a URL, get back a pixel-perfect PDF or PNG, great for invoices, receipts, and reports.

Mindmap

mindmap
  root((url-to-pdf-api))
    What it does
      URL to PDF
      HTML to PDF
      Page screenshots
    How it works
      Headless Chrome
      Puppeteer library
      Node.js service
    Configuration
      Page size margins
      Wait for JS load
      Screen or print mode
    Use cases
      Invoice generation
      Report rendering
      Page archiving
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Automatically generate PDF invoices or receipts from an HTML template by posting a URL to the API.

USE CASE 2

Take screenshots of web pages programmatically for monitoring, archiving, or visual testing.

USE CASE 3

Render JavaScript-heavy single-page apps to PDF for reporting or offline sharing.

Tech stack

Node.jsJavaScriptPuppeteerChrome

Getting it running

Difficulty · moderate Time to first run · 30min

Do not expose to the public internet without access controls, the service runs JavaScript in Chrome and can read host machine files.

In plain English

This project is a small API service that converts web pages into PDF files or screenshot images. You give it a URL or raw HTML, and it returns a rendered PDF or PNG, using a full instance of Google Chrome running in the background without a visible window (called headless Chrome). The result matches what you would get if you opened the page in a real Chrome browser and printed it to PDF. The service is built primarily for generating documents like receipts, invoices, and reports. Any web page that can be opened in Chrome can be rendered, including single-page applications that load their content via JavaScript. An option called scrollPage triggers the browser to scroll the page to the bottom before rendering, which helps capture pages that load images or content only as the user scrolls down. Configuration is done through URL query parameters or a JSON body in a POST request. You can control the output format (PDF or image), page size, margins, orientation, whether to emulate print or screen styles, and how long to wait before capturing. The API uses Puppeteer internally, a Node.js library that controls Chrome programmatically. Page size, margins, and scale are all adjustable. The README includes a prominent security warning: because the service runs JavaScript inside a real Chrome session on the server, it could be used to read files from the host machine. It should not be exposed to the public internet without careful access controls. Deployment to Heroku is available with a one-click button. Running it locally requires Node.js and access to Chrome. A Docker image from a third party is also referenced in the README.

Copy-paste prompts

Prompt 1
I'm using url-to-pdf-api to generate invoices. How do I set A4 page size, custom margins, and a 2-second wait for JavaScript to load before rendering?
Prompt 2
Show me how to POST raw HTML to url-to-pdf-api and get back a PDF file using curl.
Prompt 3
Walk me through deploying url-to-pdf-api to Heroku and locking it down so it isn't publicly accessible.
Prompt 4
My url-to-pdf-api request is missing lazy-loaded images. How do I use the scrollPage option to capture the full page?
Prompt 5
How do I configure url-to-pdf-api to return a PNG screenshot instead of a PDF?
Open on GitHub → Explain another repo

← alvarcarto on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.