Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk6 min

How to Generate PDFs from URLs with Html2Pdf.app in Node.js

Send a server-side POST request to Html2Pdf.app, handle the binary response, and save a URL as a PDF in Node.js. Learn the options, callback flow, and common fixes.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To generate a PDF from a URL with Html2Pdf.app in Node.js, send a server-side POST request to https://api.html2pdf.app/v1/generate with the page URL in the JSON html field and your API key in the X-API-Key header. Check the response status, read a successful response as binary data, and save those bytes as a PDF. The documented Node.js example uses native fetch and requires Node.js 18 or newer.

Generate and save a PDF in Node.js

Keep the API key on your server, such as in an environment variable. Do not put it in browser JavaScript, a public repository, or a client-side template. The html field can contain a publicly reachable URL or raw HTML; this example sends a URL.

As an Amazon Associate I earn from qualifying purchases.

Set the key in your shell before running the script, for example export HTML2PDF_API_KEY='your-key' on macOS or Linux. Save the following as generate-pdf.mjs and run it with node generate-pdf.mjs.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import { writeFile } from 'node:fs/promises';

const apiKey = process.env.HTML2PDF_API_KEY;
if (!apiKey) {
  throw new Error('Set the HTML2PDF_API_KEY environment variable first.');
}

const response = await fetch('https://api.html2pdf.app/v1/generate', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': apiKey,
  },
  body: JSON.stringify({ html: 'https://www.example.com' }),
});

if (!response.ok) {
  const detail = await response.text();
  throw new Error(`PDF generation failed (${response.status}): ${detail}`);
}

const pdf = Buffer.from(await response.arrayBuffer());
await writeFile('document.pdf', pdf);
console.log('Saved document.pdf');

This follows the provider’s Node.js examples. The successful synchronous response is PDF binary data, not JSON; do not call response.json() or convert it to text before saving. See the Html2Pdf.app API documentation for the endpoint and current parameter details.

#1 Best Overall
Sale
Epson Workforce ES-50 Compact & Lightweight Mobile Document Scanner
  • PORTABLE SCANNER FOR USE ON-THE-GO — The fastest and lightest mobile single-sheet-fed compact document scanner in its class¹
  • QUICK DOCUMENT SCANNING ― This Epson ultra-fast scanner scans a single page as quickly as 5.5 seconds²; Windows and Mac compatible
  • VERSATILE PAPER HANDLING ― Portable scanner scans documents up to 8.5 x 72 in; Also easily digitizes receipts and ID cards to make accounting, bookkeeping, and organizing simpler
  • INTUITIVE, HIGH-SPEED SOFTWARE — Epson ScanSmart Software³ is a smart tool allowing you to easily scan, review, and save; Stay organized easily with the help of this Epson scanner
  • EASY SETUP — USB-powered connect to your computer for quick and simple scanning; No batteries or external power supply required to operate portable document scanner; Standard Connectivity: USB 2.0

Choose the synchronous or callback workflow

Workflow What happens What your application needs Good fit
Synchronous request The request remains open during generation and returns the PDF as binary data when complete. Check the HTTP status, then save or stream the response bytes. A caller that can wait for the conversion response.
Callback job The API returns 202 Accepted to confirm queueing. The PDF arrives later in a JSON callback, base64-encoded in document. A publicly reachable HTTPS callback endpoint, idempotent handling, and optionally a state value to correlate the job. Background workflows or applications that should not hold the original request open.

The documentation does not set a general latency threshold for switching to callbacks; choose based on your application flow. Html2Pdf.app says failed callback delivery may be retried up to three times, so make your callback handler safe to receive the same completion more than once. A 202 is not the PDF itself.

Tune the PDF layout and rendering

Start with a representative page and change options only when its output calls for them. A URL can render differently depending on the page’s CSS, the availability of remote resources, and when its JavaScript finishes; the provider describes a headless Chromium renderer and notes these factors in its documentation.

Option Use and documented behavior
format Paper size: Letter, Legal, Tabloid, Ledger, or A0 through A6. The documented default is A4.
landscape Set to a boolean to request landscape orientation. The documented default is false.
width and height Set both to use custom pixel dimensions.
marginTop, marginRight, marginBottom, marginLeft Set page margins in pixels. The documented defaults are zero.
media Choose print or screen CSS media. The documented default is screen.
scale Adjust rendering scale from 0.1 to 2. The documented default is 1.
waitFor Wait additional seconds for JavaScript or asynchronous resources; the documented range is 0–10.
filename Set the returned filename.
headerTemplate and footerTemplate Supply HTML snippets for headers or footers. Allow enough top or bottom margin for them to appear.
callBackUrl and state Use a callback URL for asynchronous completion and an optional correlation value echoed back in the callback.

For example, add page settings to the same JSON body as the URL: { html: 'https://www.example.com', format: 'A4', landscape: false, media: 'screen', scale: 1 }. These are rendering controls to test against your target pages, not a guarantee that every site’s layout or resource loading will be identical. Use the API documentation for the full parameter set, including security-related options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Brother DS-640 Compact Mobile Document Scanner, (Model: DS640)
  • FAST SPEEDS - Scans color and black and white documents a blazing speed up to 16ppm (1). Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
  • ULTRA COMPACT – At less than 1 foot in length and only about 1. 5lbs in weight you can fit this device virtually anywhere (a bag, a purse, even a pocket).
  • READY WHENEVER YOU ARE – The DS-640 mobile scanner is powered via an included micro USB 3. 0 cable allowing you to use it even where there is no outlet available. Plug it into you PC or laptop and you are ready to scan.
  • WORKS YOUR WAY – Use the Brother free iPrint&Scan desktop app for scanning to multiple “Scan-to” destinations like PC, Network, cloud services, Email and OCR. (2) Supports Windows, Mac and Linux and TWAIN/WIA for PC/ICA for Mac/SANE drivers. (3)
  • OPTIMIZE IMAGES AND TEXT – Automatic color detection/adjustment, image rotation (PC only), bleed through prevention/background removal, text enhancement, color drop to enhance scans. Software suite includes document management and OCR software. (4)

Handle errors without saving an error page as a PDF

Always check response.ok before reading the body as a PDF. The provider lists these synchronous status cases:

  • 400: the source URL is inaccessible or a parameter is invalid. Check that the URL is public and that the request options are valid.
  • 401: the API key is missing or invalid. Check the X-API-Key header and server environment variable.
  • 403: a plan limit has been reached. Check your account’s current plan and usage rather than repeatedly sending the same request.
  • 500: an unhandled server error. The provider recommends retrying after a short delay with increasing intervals.

Avoid blindly retrying 400, 401, or 403 responses: fix the input, credentials, or plan issue first. For application code, log the status and a safe error detail, but do not log the API key or sensitive document contents.

Troubleshoot blank pages, missing styles, and delayed content

  • The PDF is blank or incomplete: confirm the source URL can be reached publicly by the rendering service and does not require an interactive login or an inaccessible network. Check the requested page itself before changing PDF settings.
  • CSS, images, or fonts are missing: check that the page’s linked stylesheets, fonts, images, and other remote resources are reachable to the renderer. A valid source URL alone does not guarantee all its dependencies can load.
  • JavaScript-rendered content is absent: try a small waitFor value, within the documented 0–10-second range. Waiting may help with delayed content, but it does not guarantee that every script or third-party resource will finish successfully.
  • The page uses the wrong layout: test media: 'screen' against media: 'print'; websites can define distinct screen and print styles.
  • Headers or footers do not appear: increase the corresponding page margin so the template has room.
  • Your saved file is not a PDF: verify the HTTP status before writing, and use arrayBuffer() for a successful synchronous response. A callback workflow instead sends a later JSON payload with base64 document data.

Security, encryption, and data handling

Html2Pdf.app documents a userPassword option for PDF encryption and says its PDF encryption uses 128-bit AES. It also documents permissions for actions such as printing, modifying, copying, and filling forms. Select these settings according to the document’s actual access requirements; encryption does not replace secure API-key handling.

Rank #3
Sale
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
  • STAY ORGANIZED – Easily convert your paper documents into digital formats like searchable PDF files, JPEGs, and more.Power Consumption : 2.5W or less (Energy Saving Mode: 0.7W). Suggested Daily Volume : 500 scans..Does it contain liquid: no
  • CONVENIENT AND PORTABLE –lightweight and small in size, you can take the scanner anywhere from home offices, classrooms, remote offices, and anywhere in between
  • HANDLES VARIOUS MEDIA TYPES – Digitize receipts, business cards, plastic or embossed cards, reports, legal documents, and more
  • FAST AND EFFICIENT – No technical hurdles or complicated setups here; easily scan both sides of a document at the same time, in color or black-and-white, at up to 12 pages-per-minute, and with a 20 sheet automatic feeder
  • BROAD COMPATIBILITY – Works with both Windows and Mac devices, be it laptop or computer

The provider states that generated PDFs are processed temporarily and are not permanently stored on its servers, while selected request metadata and a supplied source URL may be retained in logs. This is the provider’s own description, not an independent audit. Review its documentation, Privacy Policy, and Data Processing Agreement for details relevant to your use.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Understand credits and plan limits

Html2Pdf.app’s homepage, accessed in 2026, lists the following figures. Pricing and allowances can change, so confirm current terms with the provider before budgeting production use.

Plan Homepage figure (accessed 2026)
Free 100 credits per month; up to 1 MB per file.
Startup $9/month for 1,000 credits.
Standard $25/month for 5,000 credits.
Scale $39/month for 10,000 credits.

The homepage says each 5 MB chunk of generated document size counts as one credit. These are vendor-published plan and billing figures, not an estimate of what a particular workload will cost; document size and current account terms matter.

Rank #4
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
  • IRIScan Express, portable scanner : scans color and black and white documents a blazing speed up to 8ppm simplex. Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
  • IRIScan Express mobile scanner is powered via an included micro USB 2. 0 cable allowing you to use it even where there is no outlet available. Plug it into you PC or laptop and you are ready to scan. USB cable provided. AC Adapter not provided and not needed.
  • IRIScan flatbed scanner uses a simplex scanning mode allows for quick and straightforward scanning of single-sided documents. IRIScan with its full portable features is the ideal document scanners for computers.
  • IRIScan document scanner : Versatile scanning capabilities, including scanning to Word, PDF, and Excel formats with companion software provided Readiris OCR
  • Receipt scanner and card scanner with Additional features include scanning business cards directly to Outlook, photo scanning, and receipt scanning for efficient document management
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is a website screenshot rather than a paginated PDF, ScreenshotNeo offers a screenshot API and MCP server. A single GET request returns a PNG, JPEG, WebP, or PDF. This cURL example requests a PDF:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -d format=pdf -o page.pdf

See the ScreenshotNeo API documentation for parameters and setup. Before capture, it accepts the cookie or consent banner like a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses include X-Page-Verdict and X-Billed headers. Its MCP server gives AI agents tools including take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sign up for ScreenshotNeo free: 1,000 screenshots a month, no card.

References

Frequently Asked Questions

Can the html field contain markup instead of a URL?

Yes. The API documentation says html accepts either raw HTML or a publicly reachable URL.

Best Value
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
  • Scanner type: Document
  • Connectivity technology: USB
  • With Auto Scan Mode, the scanner automatically detects what you're scanning
  • Digitize documents and images

Does Html2Pdf.app’s Node.js example require an extra HTTP package?

No. The documented example uses native fetch in Node.js 18 or newer.

Does a callback request return the PDF in its initial response?

No. The initial response confirms acceptance with 202 Accepted; the completed PDF arrives in a later callback as base64 in the document field.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

SaleBestseller No. 3
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
BROAD COMPATIBILITY – Works with both Windows and Mac devices, be it laptop or computer; This product is not intended for scanning photographs on photo paper / photographic media
$153.00
Bestseller No. 4
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
Find our Software here : irislink.com/start; IRIScan Express is only compatible Windows platform and not macintosh
$129.00
Bestseller No. 5
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Scanner type: Document; Connectivity technology: USB; With Auto Scan Mode, the scanner automatically detects what you're scanning
$75.00

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.