October 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 ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Convert a Website URL to PDF with the PDFShift API

Send a URL in PDFShift's JSON source field, authenticate with the X-API-Key header, and save the successful response bytes as a PDF. Includes Python, cURL, and Node.js examples.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To convert a public webpage with PDFShift, send a POST request to https://api.pdfshift.io/v3/convert/pdf with the page URL in the JSON source property and your API key in the X-API-Key header. If the request succeeds, save the response body as PDF bytes.

Convert a URL to PDF with Python

This example uses Python’s requests library. Replace the API key and source URL, then run it in an environment where requests is installed.

As an Amazon Associate I earn from qualifying purchases.

import requests

api_key = "YOUR_API_KEY"
response = requests.post(
    "https://api.pdfshift.io/v3/convert/pdf",
    headers={"X-API-Key": api_key},
    json={"source": "https://www.example.com"},
)
response.raise_for_status()

with open("result.pdf", "wb") as pdf_file:
    pdf_file.write(response.content)

Use binary mode (wb) so the response bytes are written unchanged. raise_for_status() stops the example from saving an HTTP error response as though it were a finished PDF. Keep the API key out of public source code and logs; load it from a secret store or environment variable in an application.

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

Make the same request with cURL

cURL is useful for checking the request independently of your application. This writes the response body to result.pdf; inspect the HTTP status as well before treating the file as a successful conversion.

curl -X POST "https://api.pdfshift.io/v3/convert/pdf" 
  -H "X-API-Key: YOUR_API_KEY" 
  -H "Content-Type: application/json" 
  -d '{"source":"https://www.example.com"}' 
  --output result.pdf

Use Node.js with fetch

In Node.js, read the response as an array buffer before writing it to disk. This example uses the built-in fetch available in current Node.js releases.

import { writeFile } from "node:fs/promises";

const response = await fetch("https://api.pdfshift.io/v3/convert/pdf", {
  method: "POST",
  headers: {
    "X-API-Key": "YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ source: "https://www.example.com" }),
});

if (!response.ok) {
  throw new Error(`PDFShift returned HTTP ${response.status}`);
}

const pdfBytes = Buffer.from(await response.arrayBuffer());
await writeFile("result.pdf", pdfBytes);

PDFShift’s published Node.js examples also cover Got, Axios, NodeFetch, Unfetch, Bent, and Needle. The endpoint and API-key approach are the same, but each client’s response-buffer handling differs; use the binary response method documented for the client in your application.

Choose a URL or raw HTML as the source

Use a URL for a page PDFShift can fetch

Set source to the page URL when PDFShift can retrieve the page over the network. The service fetches and renders that page as part of conversion.

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.

Use raw HTML when you control the document

PDFShift’s raw-HTML guide says submitting HTML as source avoids the service’s network request to fetch the HTML, can support documents that are not publicly accessible, and may reduce conversion duration. The guide also says inline styles and JavaScript can reduce conversion duration further. Those are vendor-stated advantages, not independently measured performance guarantees. Raw HTML is often a better fit when your application already has the complete document markup; a URL is simpler when the page is already hosted and accessible.

Convert a page protected by HTTP Basic Authentication

PDFShift’s PHP guide for secured pages demonstrates an auth property containing a username and password for a page protected by Basic Authentication. The documented example supports that authentication method specifically; it does not establish how to handle OAuth, cookie-based sessions, or other login flows.

{
  "source": "https://www.example.com/private-page",
  "auth": {
    "username": "YOUR_USERNAME",
    "password": "YOUR_PASSWORD"
  }
}

Send this object as the JSON request body with the same endpoint and API-key header. Treat the credentials as secrets just as you would the API key.

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

Handle errors and save only successful conversions

The Python example raises on an unsuccessful HTTP status, and PDFShift’s PHP example saves the response only when the status is 200. Apply the same basic check in any client: confirm the request succeeded before storing the response as a PDF. The examples establish these checks, but do not provide a complete production retry policy, timeout guidance, or a comprehensive list of error codes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • HTTP error: Do not assume the body is a PDF. Surface the status to your application and inspect the error response according to PDFShift’s current API guidance.
  • Unexpected or unusable PDF: Confirm that source contains the intended URL or HTML and that your application wrote the response body as bytes rather than text.
  • Page cannot be reached: Check whether the target is publicly reachable by PDFShift or whether you need to submit raw HTML. If the page relies on an unsupported authentication method, the documented Basic Authentication example does not establish a workaround.

The implementation guides cited for this workflow do not establish current prices, quotas, timeout or retry behavior, detailed parameter limits, or a full error-code reference. Check PDFShift’s current service documentation for those operational details before designing production limits or retry logic.

Or skip the browser setup

If you need a screenshot rather than a PDF document, ScreenshotNeo offers a one-request website screenshot API; it is an alternative, not a replacement for PDFShift’s URL-to-PDF workflow. Its API can return PNG, JPEG, WebP, or PDF. For a screenshot capture, the following cURL request saves the response as a WebP image. See the ScreenshotNeo API documentation for its options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://www.example.com -o shot.webp
  • Cookie and consent banners, newsletter popups, and chat widgets are removed before capture; each step can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; responses include page-verdict and billing headers.
  • An MCP server lets AI agents use screenshot tools, including Claude, Cursor, and other MCP clients.
  • The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.

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
Windows Errors? Fix Them Before They SpreadFree repair 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.