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 DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk5 min

How to Generate a PDF from HTML Content Instead of a URL with Html2Pdf.app

Convert generated HTML directly to a PDF with Html2Pdf.app: use the JSON html field, send your API key securely, and handle the binary response correctly.

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.

To convert HTML your application has already generated, send it in the html field of an authenticated JSON POST request to https://api.html2pdf.app/v1/generate. A successful synchronous response is the PDF as binary data, so save or stream the response bytes rather than trying to parse JSON. You do not need to publish the HTML at a URL first.

Send raw HTML in the required html field

The API accepts either raw HTML markup or a publicly reachable page URL in html. For content assembled inside your application, use the markup itself. Send JSON with Content-Type: application/json and authenticate with your API key in the X-API-Key header. The API documentation recommends POST for raw markup; long HTML in GET query parameters requires URL encoding and is a poor fit for templates. See the API documentation and cURL API guide for current request details.

As an Amazon Associate I earn from qualifying purchases.

cURL

This vendor-provided example sends inline markup and writes the binary response to invoice.pdf:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl --fail --show-error 
  --request POST https://api.html2pdf.app/v1/generate 
  --header 'Content-Type: application/json' 
  --header 'X-API-Key: <your-api-key>' 
  --data '{
    "html": "<h1>Invoice INV-1042</h1><p>Total: $240.00</p>",
    "format": "A4",
    "marginTop": 40,
    "marginRight": 32,
    "marginBottom": 40,
    "marginLeft": 32
  }' 
  --output invoice.pdf

Replace the example key with your own. With --fail, cURL treats an HTTP error as a failed command instead of silently saving an error response as if it were a PDF.

#1 Best Overall
Brother Compact Monochrome Laser Printer, HLL2395DW, Flatbed Copy & Scan, Wireless Printing, NFC with Refresh Subscription Free Trial and Amazon Dash Replenishment Ready
  • Engineered for convenience – This new Brother Monochrome Laser Printer is conveniently equipped with a flatbed scan glass for quick copying and scanning. Mobile Device Compatibility AirPrint, Google Cloud Print 2.0, Brother iPrint and Scan, Mopria, Cortado Workplace
  • Optimized for efficiency – Engineered with new features, the HL L2395DW laser printer (replacement for the HLL2380DW) and has been optimized for efficiency, allowing you to print up to 36 pages per minute(1)
  • Faster, high quality prints: This monochrome laser printer is built with a 250 sheet paper capacity that helps improve efficiency due to less time spent refilling trays. It also handles both letter and legal sized paper. Power Source AC 120V 50/60Hz.Machine Noise (Ready/Printing): 30dB / 50dB
  • Cloud based print & scan – Print from and scan to popular Cloud services directly from the 2.7" color touchscreen, including Dropbox, Google Drive, Evernote, OneNote, and more(4)
  • Wireless printing & exceptional support – This printer’s simple to connect wireless technology allows you to submit print jobs from your laptop, smartphone, desktop, and tablets(2). The "Touch to connect" printing with NFC delivers added convenience(3).

Python

Use a JSON serializer rather than interpolating HTML into a JSON string. This handles quotes, newlines and other characters correctly. The example assumes the API key is stored in an environment variable:

import os
import requests

api_key = os.environ["HTML2PDF_API_KEY"]
html = "<h1>Invoice INV-1042</h1><p>Total: $240.00</p>"

response = requests.post(
    "https://api.html2pdf.app/v1/generate",
    headers={
        "Content-Type": "application/json",
        "X-API-Key": api_key,
    },
    json={
        "html": html,
        "format": "A4",
        "marginTop": 40,
        "marginRight": 32,
        "marginBottom": 40,
        "marginLeft": 32,
    },
    timeout=90,
)
response.raise_for_status()
with open("invoice.pdf", "wb") as pdf_file:
    pdf_file.write(response.content)

The json= argument serializes the request body. raise_for_status() prevents an HTTP error body from being written to the output file, and wb preserves the PDF bytes.

Node.js

In a server-side Node.js environment with fetch, serialize the object as JSON, check the status, and write the response as bytes:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Brother MFC-L3710CW Compact Digital Color All-in-One Printer Providing Laser Printer Quality Results with Wireless, Amazon Dash Replenishment Ready
  • FAST PRINT AND SCAN: The Brother MFC-L3710CW lets you get things done with up to 19 ppm print speed and scans up to 29 ipm in black and 22 ipm in color
  • AFFORDABLE AND FLEXIBLE COLOR PRINTING: Affordably print professional quality, rich, vivid color documents with laser printer quality. The 250 sheet adjustable paper tray helps minimize refills and the manual feed slot handles varied printing needs
  • 3.7” COLOR TOUCHSCREEN: Print from and scan to popular cloud apps directly from the 3.7" color touchscreen including Dropbox, Google Drive, Evernote, OneNote and more. Save time by creating custom shortcuts on the touchscreen for your most used features.
  • PRINT AND CONNECT YOUR WAY: Print wirelessly from your desktop, laptop, smartphone and tablet with built-in wireless, and Wi-Fi Direct or connect locally to a single computer via USB interface.
  • UNIT DIMENSIONS (WxDxH): 16.1” W x 18.7” D x 16.3” H
import { writeFile } from "node:fs/promises";

const apiKey = process.env.HTML2PDF_API_KEY;
if (!apiKey) throw new Error("Set HTML2PDF_API_KEY first");

const html = "<h1>Invoice INV-1042</h1><p>Total: $240.00</p>";
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,
    format: "A4",
    marginTop: 40,
    marginRight: 32,
    marginBottom: 40,
    marginLeft: 32,
  }),
});

if (!response.ok) {
  throw new Error(`Html2Pdf.app returned HTTP ${response.status}: ${await response.text()}`);
}
await writeFile("invoice.pdf", Buffer.from(await response.arrayBuffer()));

Keep the key on a trusted server or job runner. Do not put it in browser JavaScript, a public repository or a client-side template.

Choose synchronous delivery or a callback

Synchronous PDF response

For an ordinary conversion, make the POST request and wait for the response. On success, the body contains PDF binary data, not a JSON object. Save those bytes to a file or stream them to the part of your application that needs the document. Check the HTTP status before treating the body as a PDF.

Asynchronous callback

For background workflows or jobs that may take longer, the documentation describes a callBackUrl option. The API returns 202 Accepted for the queued request, then POSTs to the callback URL with the PDF base64-encoded in the document field. Callback delivery may be retried, so make callback processing idempotent: for example, record a stable job identifier and avoid saving or triggering the same completed job twice. Confirm the current callback payload and parameter requirements in the API documentation before relying on them.

Rank #3
MixPad Free Multitrack Recording Studio and Music Mixing Software [Download]
  • Create a mix using audio, music and voice tracks and recordings.
  • Customize your tracks with amazing effects and helpful editing tools.
  • Use tools like the Beat Maker and Midi Creator.
  • Work efficiently by using Bookmarks and tools like Effect Chain, which allow you to apply multiple effects at a time
  • Use one of the many other NCH multimedia applications that are integrated with MixPad.

Set page size, orientation, margins and CSS mode

The documented layout controls include page format or dimensions, orientation, margins, and screen or print media mode. The cURL example uses A4 and margins in the request body. Check the current parameter reference for accepted values and limits; do not assume every browser print option or CSS feature is exposed by the API.

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

The service says it renders using headless Chromium. That means the output can depend on whether referenced stylesheets, fonts and images are reachable by the renderer, which CSS media mode is selected, and when JavaScript finishes loading. If the PDF should use print styles, select the documented print media mode; if it should match screen styling, use the screen mode. Ensure any external assets required by the markup are accessible to the rendering service.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common errors and practical fixes

HTTP response or symptom Likely cause What to do
400 Invalid parameter or inaccessible source URL. Check parameter names and values. If using a URL, verify it is publicly reachable; for application-generated content, send the HTML markup directly in the JSON html field.
401 Missing or invalid API key. Check that the X-API-Key header is present and contains the correct key. Keep it server-side.
403 A limit on the current plan. Review the applicable plan limit before retrying or changing the job.
500 Unhandled server error. Inspect the response and retry cautiously if appropriate. The documentation identifies the status but does not establish a guaranteed recovery time.
PDF is blank or styles are missing Rendering dependencies cannot be reached, media mode differs from the intended styling, or JavaScript content was not ready when captured. Check asset access, choose the intended screen or print media mode, and adjust the page’s load timing so required content is ready before rendering.
Saved file is not a valid PDF An HTTP error response may have been saved as though it were a successful PDF. Check status before writing bytes; use cURL’s --fail, Python’s raise_for_status(), or Node’s response.ok check.

Do not repeatedly retry 400, 401 or 403 without fixing the invalid request, credentials or plan constraint first.

Rank #4
Corel PDF Fusion Software
  • Save money by using PDF Fusion to view over 100 file formats without having to purchase additional software
  • Merge incompatible files quickly and easily by dragging and dropping in PDF Fusion to create a new PDF documents
  • Save time with PDF Fusion's editing tools to reuse the content from existing documents without starting from scratch

Test a template without building an API client

For a manual trial, Html2Pdf.app provides a browser converter with an HTML input mode and preview/download controls. The vendor describes it as a free interactive testing tool and recommends the API for automated or production conversion. See the Html2Pdf.app converter.

Or skip the browser setup

Html2Pdf.app is for rendering HTML into a PDF. If what you need is instead a screenshot of a webpage, ScreenshotNeo offers a one-request screenshot API:

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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation. Cookie banners are accepted and removed before capture, along with known newsletter popups and chat widgets; those steps can be turned off. Bot checks, blank pages and failed loads are never billed, and responses identify the page verdict and billing status. An MCP server lets AI agents use screenshot tools. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots. Sign up free for ScreenshotNeo.

Frequently Asked Questions

Can I send HTML content instead of a URL?

Yes. Put the raw markup in the required JSON html field and POST it to the generate endpoint.

What does a successful synchronous request return?

The PDF as binary response data, which your code should save or stream as bytes.

Quick Recap

Bestseller No. 3
MixPad Free Multitrack Recording Studio and Music Mixing Software [Download]
MixPad Free Multitrack Recording Studio and Music Mixing Software [Download]
Create a mix using audio, music and voice tracks and recordings.; Customize your tracks with amazing effects and helpful editing tools.
Bestseller No. 4

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.

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

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

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.