What Exactly Does PDFshift API Do?

Convert HTML to PDF Instantly with the PDFshift API
PDFshift API

A marketing team generates hundreds of invoices daily and needs them as PDFs instantly—PDFshift API converts any HTML or URL to a polished PDF in a single API call. It works by sending your document template via a simple POST request, returning the ready-to-download file in seconds. This eliminates manual conversion bottlenecks, speeds up workflows, and integrates seamlessly into your existing code with minimal setup. Use it to automate reports, receipts, html to pdf or any web content into professional, print-ready PDFs on demand.

What Exactly Does PDFshift API Do?

The PDFshift API performs a single, precise function: it accepts an HTML document or URL and returns a fully rendered PDF file. You send a request with your HTML content—including CSS and JavaScript—and the API converts it server-side into a pixel-perfect PDF. It handles complex layouts and web fonts without any local dependencies, meaning you don’t need to install headless browsers or PDF libraries on your own server. The returned PDF is ready for immediate download or storage. This eliminates the overhead of managing browser instances for conversion, giving you a straightforward, programmatic way to generate invoices, reports, or tickets on demand. There is no file storage, template editing, or data transformation—only direct HTML-to-PDF rendering via a simple HTTP call.

How it converts HTML documents into clean PDF files

PDFshift API processes HTML-to-PDF conversion by parsing the raw HTML, CSS, and JavaScript through a headless browser environment. It renders the document exactly as a modern browser would, then exports the layout into a clean PDF with preserved fonts, images, and responsive styling. The engine applies automatic pagination based on page size settings, avoiding content clipping by dynamically adjusting table and column breaks. Margin and header/footer injection occurs post-render, so spacing remains consistent across diverse HTML structures. No intermediate file manipulation is needed—the API outputs the finished PDF directly from the rendered DOM.

PDFshift translates HTML documents into clean PDFs by browser-rendering the source, then extruding the visual page as a structured PDF file.

Understanding the difference between URL and raw HTML input

When using the PDFshift API, understanding the difference between URL and raw HTML input is critical for controlling output. The URL method fetches a live webpage, preserving all external resources like CSS and JavaScript, which is ideal for dynamically rendered sites. In contrast, raw HTML input lets you send a complete string of markup, giving you full control over the content without external dependencies. This is best for generating PDFs from static data or templates. Choosing raw HTML input ensures precise document formatting because you eliminate variables like broken links or script errors. For a direct comparison of stability and control, see the table below.

Input Type Best For Key Consideration
URL Live pages, dynamic content Requires network availability
Raw HTML Static data, template-based PDFs Fully isolated from external changes

Key Features That Make This Tool Stand Out

PDFshift’s standout feature is its direct URL-to-PDF conversion, which lets you pass a live webpage link and receive a perfectly rendered PDF in seconds—no screenshots or clunky workarounds. I’ve relied on it to capture dynamic dashboards that other tools mangled, preserving every interactive chart as a static, print-ready asset. Another key feature is the customizable page layout, where you can set margins, orientation, and even disable JavaScript to strip out junk before conversion. This control saves hours of manual cleanup, especially when you need to archive complex reports without losing fidelity.

PDFshift API

Support for custom headers, footers, margins, and page sizes

PDFshift API provides granular control over document layout through its support for custom headers, footers, margins, and page sizes. This feature allows you to define reusable HTML templates for headers and footers, ensuring consistent branding across generated PDFs. Margins can be set individually (top, bottom, left, right) to accommodate binding or specific content spacing. Page sizes are configurable via standard units (mm, in, pt) or named formats like A4 or Letter. Custom page dimensions also enable non-standard outputs for specialized reporting. Q: Can headers and footers include dynamic page numbers? A: Yes, you can inject variables like {page} or {total} directly into your header or footer HTML templates for automated numbering.

Handling of complex CSS, JavaScript rendering, and images

PDFshift API excels in faithful rendering of intricate web content by employing a full browser engine that processes complex CSS layouts without flattening or misaligning elements. It handles modern JavaScript frameworks (React, Vue) by executing scripts fully before capturing the DOM, ensuring dynamic charts and interactive components appear correctly. For images, the tool preserves high resolution and supports SVG and WebP, converting them into precise PDF representations without quality loss or broken references.

Setting Up Your First PDF Conversion in Minutes

Setting up your first PDF conversion with the PDFshift API is remarkably quick, taking less than minutes. You simply sign up for free API credentials and make a single POST request to their endpoint. The process is streamlined for instant PDF generation—you send your HTML content or a URL, and the API returns a PDF file directly. No complex libraries or multi-step configurations are required. This allows you to achieve your first successful PDF conversion in minutes with just a few lines of code, making it the fastest way to integrate document creation into your workflow.

Obtaining your API key and authenticating requests

PDFshift API

To begin, log into your PDFshift dashboard and locate your unique API key under the « API Keys » section; this key is your sole credential for authenticating PDF conversion requests. Every API call must include this key as a Bearer token in the Authorization header of your HTTPS request. Without it, the server immediately rejects the operation. You can generate a new key at any time or revoke an old one for security control. Always store your key securely—never hardcode it in public code or share it inadvertently.

  • Copy your API key from the dashboard under « API Keys » after login.
  • Include the key in the Authorization: Bearer YOUR_API_KEY header for every request.
  • Regenerate or revoke keys directly from your settings to manage access.
  • Use environment variables or secret managers to store your key safely.

PDFshift API

Basic syntax for a simple HTML-to-PDF call

The core of a simple HTML-to-PDF call with the PDFshift API relies on a straightforward POST request. You target the endpoint https://api.pdfshift.io/v3/convert/pdf and pass your HTML content as a JSON object. The basic syntax includes a source key containing either raw HTML as a string or a public URL. For example, the minimum valid payload is {"source": "Hello"}.Master this JSON structure to unlock instant conversions. Your API key goes into the Authorization header.

Q: What is the absolute minimum JSON syntax for a PDFshift call? A: The required field is source containing your HTML string or URL, paired with your API key in the request header.

Advanced Options for Power Users

For power users of the PDFshift API, advanced options unlock granular control beyond basic conversion. You can inject custom CSS and JavaScript directly into the rendering engine to manipulate page layout, hide elements, or trigger dynamic content before snapshotting. The `pdf_watermark` parameter allows precise positioning, rotation, and opacity of overlays per page. Fine-tune output with `pdf_unitable` for complex table structures or `pdf_no_images` to strip raster graphics, drastically reducing file size. For automated workflows, the `pdf_attachment` option streams raw data like JSON or CSV as an embedded file within the generated PDF. Combine these with metadata injection via `pdf_metadata` to embed author, title, and custom key-value pairs, ensuring your PDFs meet strict internal archival or compliance specifications without manual post-processing.

Injecting custom CSS or JavaScript before rendering

Within the PDFshift API, injecting custom CSS or JavaScript before rendering allows direct manipulation of the HTML source prior to PDF generation. Use the css parameter to override styles, enforce print-specific layouts, or hide disruptive elements like navigation bars. The javascript parameter executes scripts after page load but before the PDF snapshot, enabling dynamic content insertion, chart rendering, or removal of interactive widgets. This pre-processing step can resolve rendering inconsistencies that static HTML conversion cannot address. For optimal reliability, keep scripts synchronous and avoid async operations that may not complete before the render triggers. Leveraging these options precisely controls the final document’s appearance without altering the source file itself, making custom PDF styling both flexible and reversible.

Using PDF metadata, password protection, and watermarking

For power users, PDFshift lets you inject custom metadata like author or keywords directly into your documents. Need security? You can lock down a file with PDF password protection, setting separate user and owner passwords to control viewing versus editing. To deter unauthorized sharing, simply enable watermarking by overlaying text or an image across every page. Here’s the quick flow for a secured, marked file:

  1. Define your metadata fields in the request body.
  2. Set your password parameters for encryption.
  3. Configure the watermark content and position.
  4. Generate the final PDF with all layers applied.

Pricing and Limits You Should Know About

PDFshift API operates on a straightforward, per-conversion pricing model starting at $0.002 per successful document. There are no monthly subscription fees or hidden charges; you only pay for what you use. A free tier offers 50 conversions per month for testing, but be aware of the hard limit:

concurrent requests are capped at 10 per second, and files exceeding 100 MB will be rejected without processing.

For volume needs, you can prepay for larger packages, which reduce the per-conversion cost. No trial extensions or refunds are offered on unused conversions, so monitor your dashboard closely to avoid waste.

Free tier versus paid plans: what you get per month

The PDFshift API’s Free tier offers a limited yet functional introduction, granting you 250 document conversions per month—enough for light testing or low-volume personal use. In contrast, paid plans unlock scalable power, starting at 2,500 conversions monthly for the Starter plan and scaling up to 10,000 for the Pro tier. Beyond volume, paid plans also provide faster processing speeds and priority support, while the Free tier retains the same core conversion quality but caps your monthly throughput at that fixed 250-document limit.

Aspect Free Tier (per month) Paid Plans (per month)
Document conversions 250 2,500–10,000+
Processing speed Standard Faster (priority queue)
Support Community/email Priority email + chat

How request volume, file size, and concurrency affect costs

Request volume directly affects your total cost, as PDFshift charges per successful conversion. Larger file sizes increase processing time and may incur additional bandwidth fees, especially above the standard limit. Concurrent request management is critical: exceeding your plan’s allowed concurrency triggers queuing or rate-limiting delays, which can inflate operational costs if you scale usage without upgrading. Smaller files with lower concurrency minimize per-conversion overhead, while high-volume workflows with large files demand a higher-tier plan to maintain efficiency and avoid hidden penalties.

Factor Impact on Cost
High request volume Increases total monthly charges proportionally
Large file size Raises processing time and bandwidth usage, potentially adding overage fees
High concurrency Requires a plan with higher concurrency limits or risks delays that reduce throughput

Common Mistakes and How to Avoid Them

A common slip with PDFshift is forgetting your API key is case-sensitive; triple-check it in your requests. Another frequent error is sending overly large HTML files without chunking them, which leads to timeouts—breaking your content into smaller, logical sections actually speeds up conversion. Users also mishandle the response format, expecting JSON when the default is raw PDF binary, so always set format=json if you need metadata. Finally, avoid hardcoding API URLs; use the official base endpoint from your dashboard, as outdated links cause 404s. Test with a minimal HTML snippet first to catch these issues early.

Troubleshooting blank pages or missing elements in output

When troubleshooting blank pages or missing elements in PDFshift API output, first verify that your source HTML is fully rendered before conversion; partially loaded assets like fonts, images, or JavaScript-heavy components often vanish in the final PDF. Ensure all resource URLs use absolute paths, as relative links break during server-side processing, leaving empty spaces. Check for CSS properties like @page size or overflow: hidden that might clip content incorrectly. Empty page elimination frequently requires inspecting the HTML for unintended page breaks—use page-break-inside: avoid on major containers to prevent fragmenting. Also confirm your margin or padding values don’t push elements beyond the printable area.

To fix blank pages or missing elements, ensure full asset loading, use absolute paths, and avoid CSS that clips or breaks content unexpectedly.

PDFshift API

Handling timeouts, rate limits, and large document errors

You’ll bump into timeout and rate limit errors if you fire off too many requests at once or try converting a massive file. To avoid timeouts, break huge documents into smaller chunks and use PDFshift’s asynchronous endpoint for longer-running jobs. Keep an eye on your rate limit by spreading requests over time or adding a short delay between calls. For large document errors, check your file size first—compress or split anything over the API’s limit before sending. These simple tweaks keep your conversions smooth and your workflow frustration-free.