Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk6 min

How to Convert a URL to PDF with the DocRaptor API

A practical DocRaptor URL-to-PDF guide with cURL, Python, and Node.js examples, authentication, binary response handling, test mode, and JavaScript options.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To convert a webpage URL to PDF with DocRaptor, send a JSON POST request to https://api.docraptor.com/docs with document_url set to the page address and type set to pdf. Authenticate with your DocRaptor API key as the HTTP Basic Auth username and a blank password. A successful synchronous request returns PDF bytes, which your application should save or stream as a file.

Make a URL-to-PDF request

The current request uses type; older integrations may use document_type, but new code should use the current name. Keep the API key on a server you control rather than embedding it in browser code.

As an Amazon Associate I earn from qualifying purchases.

cURL

Set DOCRAPTOR_API_KEY in your environment before running this command. The example enables test mode so you can inspect the PDF; test output is watermarked.

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.
curl --user "$DOCRAPTOR_API_KEY:" 
  --fail --silent --show-error 
  --header "Content-Type: application/json" 
  --data '{"test":true,"type":"pdf","document_url":"https://example.com/page"}' 
  https://api.docraptor.com/docs 
  --output page.pdf

After verifying the result, remove "test":true for an unwatermarked production PDF. DocRaptor’s API overview describes the JSON POST endpoint at https://docraptor.com/documentation/api; the API reference documents request fields and rendering options at https://docraptor.com/documentation/api#doc.

Python

Use a binary response and write its content directly to a file. Install the dependency with python -m pip install requests. Set DOCRAPTOR_API_KEY in the environment first.

import os
import requests

api_key = os.environ["DOCRAPTOR_API_KEY"]
response = requests.post(
    "https://api.docraptor.com/docs",
    auth=(api_key, ""),
    headers={"Content-Type": "application/json"},
    json={
        "type": "pdf",
        "document_url": "https://example.com/page",
        "test": True,
    },
    timeout=120,
)
response.raise_for_status()

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

For production, change "test": True to False or omit it. The official Python tutorial covers HTML-to-PDF setup and says paid plans start at $15/month; verify current pricing on DocRaptor’s site before choosing a plan: https://docraptor.com/documentation/python.

Node.js

This example uses Node’s built-in fetch and writes the response bytes to a file. It requires a Node version with global fetch support. Set the key in DOCRAPTOR_API_KEY.

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.DOCRAPTOR_API_KEY;
if (!apiKey) throw new Error("Set DOCRAPTOR_API_KEY first");

const response = await fetch("https://api.docraptor.com/docs", {
  method: "POST",
  headers: {
    "Authorization": `Basic ${Buffer.from(`${apiKey}:`).toString("base64")}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    type: "pdf",
    document_url: "https://example.com/page",
    test: true,
  }),
});

if (!response.ok) {
  const errorBody = await response.text();
  throw new Error(`DocRaptor returned HTTP ${response.status}: ${errorBody}`);
}

await writeFile("page.pdf", Buffer.from(await response.arrayBuffer()));

Remove test: true for an unwatermarked production document. Don’t treat the successful body as JSON or text: it is the PDF data.

Rank #2
Sale
Adobe Acrobat 6 PDF For Dummies
  • Used Book in Good Condition

Choose URL input, PDF output, and authentication

  • Use document_url when DocRaptor should fetch a webpage. The API also supports document_content for inline document content, but that is a different input workflow.
  • Set type to pdf to request a PDF. The API reference notes document_type as a name used by older integrations.
  • Authenticate with HTTP Basic Auth, using your API key as the username and an empty password. DocRaptor identifies this as its preferred REST authentication method.

For a synchronous request, check the HTTP status before saving the response. A successful response contains binary PDF data. DocRaptor says errors return an XML error message; do not write that error body to a file with a .pdf extension.

Test safely, then make an unwatermarked PDF

Set test: true while developing or adjusting a document. Test PDFs carry a watermark, so remove the flag or set it to false when the final file must be unwatermarked. The official URL-to-PDF and Python documentation describe test mode and its watermark: https://docraptor.com/documentation/try-it-out and https://docraptor.com/documentation/python.

The tutorial pages show a public test key for test-mode use. Treat that as a testing convenience, not a production credential. Store your own live key in server-side configuration or a secrets manager, and make DocRaptor requests from your backend. DocRaptor’s general documentation warns that client-side code exposes the API key: https://docraptor.com/documentation.

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

Enable JavaScript only if the page needs it

JavaScript rendering is disabled by default, which avoids rendering work when the page is already available as HTML. If the URL depends on client-side JavaScript—for example, to populate a chart or page content—add "javascript": true to the JSON request.

DocRaptor’s API reference describes its JavaScript engine and a completion signal, docraptorJavaScriptFinished(), for delayed or asynchronous code. Avoid enabling both available JavaScript engines together unless your particular document requires that arrangement; the reference warns that code may be evaluated twice. See the API reference and the JavaScript tutorial.

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

Handle the response and choose a request mode

Synchronous PDF bytes

The examples above use the normal synchronous response: after a successful request, save or stream the response body as binary data. DocRaptor’s API overview says the X-DocRaptor-Num-Pages response header contains the PDF page count. The same overview documents the endpoint and response modes at https://docraptor.com/documentation/api.

Hosted and asynchronous documents

DocRaptor documents alternatives to receiving the PDF bytes directly: hosted documents return a public URL, while asynchronous document requests return a status_id that you use to retrieve the document. These are distinct response flows from the synchronous file-writing examples here; select one only if your application’s delivery or processing pattern calls for it. Refer to the API overview for the corresponding behavior.

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

Troubleshoot common failures

  • The saved file is XML or is not a valid PDF: The request may have failed and returned DocRaptor’s XML error body. Check the HTTP status and inspect the response before writing it as a PDF.
  • DocRaptor cannot download the page: The API reports errors such as “Error downloading document content from supplied url.” Confirm the URL is correct and reachable by DocRaptor, and that it serves the intended page rather than an access-denied or unrelated response.
  • The PDF is missing charts or other page content: If the page creates that content in the browser, JavaScript is likely required. Enable javascript: true and, for delayed work, use the documented completion signal where appropriate.
  • The PDF has a watermark: This is expected when test mode is enabled. Remove test: true for the production request.
  • The request is rejected as unauthorized: Check that Basic Auth uses the API key as username and a blank password, and that the key is the correct account credential.
  • The API key appears in browser source: Move the request to a server-side agent. A key embedded in a public website can be exposed to visitors.

Or skip the browser setup

If your goal is a clean screenshot or PDF capture of a URL rather than DocRaptor’s document-conversion workflow, ScreenshotNeo provides a one-request screenshot API. For example, this cURL request saves a WebP screenshot:

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 for request options. It accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server gives AI agents tools to take screenshots, get page information, and capture PDFs.

ScreenshotNeo’s free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for ScreenshotNeo free.

Quick Recap

SaleBestseller No. 2
Adobe Acrobat 6 PDF For Dummies
Adobe Acrobat 6 PDF For Dummies
Used Book in Good Condition
$13.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.

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
PC Slower Than It Used to Be?Free scan - under a minute
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.