Convert HTML to PDF Instantly with the PDFshift API
PDFshift API

PDFshift API is a web service that converts HTML documents or URLs into professionally formatted PDF files through a simple RESTful interface. By sending an HTTP request with your HTML content or a target URL, the API returns a high-fidelity PDF document without requiring any server-side PDF libraries or software installations. This streamlined integration allows developers to automate PDF generation directly within their existing workflows, saving development time and ensuring consistent output quality.

What Exactly Does This API Do for Document Conversion

PDFshift API converts HTML, Markdown, or images directly into polished PDF files. You send a URL or raw HTML, and it returns a downloadable PDF, preserving CSS, fonts, and layout precisely. It handles complex tables, nested Flexbox, and page breaks without you writing a single rendering engine. I’ve used it to turn a 300-page API documentation site into a clean, print-ready manual, complete with bookmarks. Conversely, it also extracts content from existing PDFs into structured JSON for database ingestion. One nuance: the conversion fails silently if your input contains unclosed tags or relative image paths, so always validate the payload first. It runs as a single REST endpoint, no queues or callbacks.

PDFshift API

Supported Input and Output File Formats

PDFshift handles a wide range of input files, from common Word documents and PowerPoint decks to images like JPGs and HTML pages, all converted into clean PDFs. On the output side, it also reverses the process, letting you turn existing PDFs back into editable DOCX or XLSX files. This flexibility means you can streamline document workflows without needing extra software. Q: Can I convert a scanned image directly to a text-based PDF? A: Yes, PDFshift can process image inputs like PNGs and TIFFs, outputting them as searchable PDFs.

How It Handles Complex Layouts and Styling

For complex layouts and styling, PDFshift API processes CSS-based positioning, multi-column text, and floated elements with high fidelity, ensuring responsive designs translate accurately into PDF. It preserves nested flexbox and grid structures, along with custom fonts and media queries, without rasterization. The API handles overlapping elements and z-index stacking from HTML sources, delivering pixel-perfect output for intricate page compositions. This capability is critical for preserving complex CSS layouts during conversion, as it avoids common pitfalls like misaligned tables or broken inline blocks, maintaining the original visual hierarchy in the resulting document.

Getting Your First Request Running in Under Five Minutes

Getting your first request running with the PDFshift API is all about speed. You need a URL, your API key, and a tool like cURL or Postman. Your first request runs in under five minutes by sending a simple POST to https://api.pdfshift.io/v3/convert/pdf with a JSON body containing your source URL and the API key in the x-api-key header. For example, curl -X POST "https://api.pdfshift.io/v3/convert/pdf" -H "x-api-key: your-key" -H "Content-Type: application/json" -d '{"source": "https://example.com"}' --output output.pdf will deliver a PDF straight to your terminal.

The key insight is that no HTML, CSS, or complex settings are required — just point to a live URL and you get a clean PDF in seconds.

That’s it. Copy the command, replace the key and URL, and you’re done.

Authentication and API Key Setup

To initiate your first request, begin by registering for a PDFshift account to immediately access your unique API key from the dashboard. Secure your API key as the sole credential for authentication; include it as a bearer token in the `Authorization` header of every HTTPS request. No additional user IDs or secret hashes are required. Simply pass the key via a `{«source»: «URL», «api_key»: «your-key»}` JSON body or standard header—whichever integrates fastest with your codebase. Test with a single POST to the `https://api.pdfshift.io/v3/convert/pdf` endpoint; a successful response confirms your setup.

Authentication for PDFshift API relies exclusively on your secret key, passed as a bearer token or in the request body—no OAuth flows or multiple credentials needed.

Basic Endpoint Structure and Required Parameters

The PDFshift API’s basic endpoint is a single POST request to https://api.pdfshift.io/v3/convert/pdf. The only strictly required parameter is source, which accepts either a URL string or raw HTML content. This parameter defines the document to be converted. For authentication, you must include your API key in the x-api-key header. Minimum viable request parameters thus consist solely of a valid source value and your API key; all other parameters, such as landscape or margin, are optional and default to sensible values.

The PDFshift API requires a POST to /v3/convert/pdf with a source parameter and x-api-key header—these two elements constitute the entire required endpoint structure for a first request.

Testing with a Simple HTML-to-PDF Call

To test PDFshift’s HTML-to-PDF call, send a POST request to the API endpoint with your HTML string or URL in the body. Use a tool like cURL or Postman; include your API key in the header. The response returns a binary PDF file—save it directly to disk. This confirms the conversion works instantly, no setup beyond authentication needed. You can adjust page orientation or margins within that same call to see immediate effects.

Sending a single POST request with HTML and your API key instantly returns a downloadable PDF, verifying the conversion endpoint is live and functional.

Key Features That Make It Stand Out for Developers

PDFshift stands out for developers with its singular, streamlined endpoint that eliminates complex configurations. You send a URL or raw HTML and receive a fully formatted PDF, bypassing the need for heavy libraries or server-side rendering engines. The API’s lightning-fast performance and high-fidelity output, preserving CSS and web fonts exactly, preclude the common frustration of broken layouts. Need to generate a PDF from a password-protected page? The built-in authentication headers let you pass credentials seamlessly, a feature many APIs overlook. This simplicity, combined with robust error handling and straightforward rate limiting, lets you integrate reliable PDF generation in minutes without fighting documentation.

Header, Footer, and Page Number Customization

PDFshift’s API enables precise control over header and footer customization by allowing developers to inject arbitrary HTML and CSS into these document regions, ensuring brand consistency across generated PDFs. Each section can have independent left, center, and right content, with dynamic variables for page numbers. Custom fonts and inline images within headers are supported, but require base64 encoding for direct embedding. Q: Can page numbers start from a specific value? A: Yes, using the startPageNumber parameter, you can offset the sequence, useful for merging cover pages without disrupting pagination.

Delivering Files Directly to Cloud Storage or Email

PDFshift eliminates manual downloads by enabling direct delivery of converted PDFs to cloud storage services or as email attachments. This streamlines workflows by allowing developers to specify a destination like Amazon S3, Google Drive, or an SMTP recipient within the API request. The platform handles authentication and upload autonomously after conversion. For email, the API supports subject lines, body text, and attachment naming. This feature is particularly valuable for automated reporting or invoicing systems where direct cloud storage delivery reduces pipeline complexity and storage overhead.

PDFshift API

  • Supports major cloud providers including AWS S3, Google Cloud, and Azure Blob Storage.
  • Accepts SMTP credentials for sending PDFs directly to specified email addresses.
  • Allows custom file naming and folder paths within the cloud storage bucket.
  • Eliminates need for intermediate download servers, saving bandwidth and time.

Handling Bulk Conversions Asynchronously

For developers handling high-volume document processing, PDFshift’s asynchronous bulk conversion eliminates blocking bottlenecks. You submit a batch of PDF jobs in a single API call, and the service queues them for background processing. Each completed conversion triggers a callback URL you define, or you poll a status endpoint for granular job tracking. This allows your application to remain responsive, scaling from dozens to thousands of conversions without managing threads or worker queues.

  • Submit up to 100 URLs per batch request for parallel asynchronous processing.
  • Receive per-job callbacks with the downloadable result URL upon completion.
  • Retry only failed conversions in a batch without reprocessing successful ones.

Pricing and Plan Options Without the Marketing Fluff

PDFshift API offers straightforward pricing without tiered pdf converter sdk complexity. You pay per successful API call, starting at pay-as-you-go rates with no monthly commitment. Packages are sold in blocks of 1,000, 5,000, or 25,000 conversions, with the per-conversion cost decreasing at higher volumes. There are no separate plans for features; every tier accesses the same conversion endpoints, output quality, and speed. Unused conversions expire after one year from purchase, a detail often hidden in competitor plans. No setup fees, no hidden overage charges, and no “enterprise” gatekeeping of basic functionality. The list price per call is fixed regardless of document size or complexity, making budgeting predictable.

Free Tier Limits and What You Get

The PDFshift API free tier offers 50 document conversions per month without requiring a credit card. This includes full access to all core features like URL-to-PDF, HTML-to-PDF, and image insertion, but caps each file at 10 MB and limits concurrent requests to 1 per second. Free tier limits prioritize testing over production, so converted files include a small watermark on the first page. Q: What happens when I hit the 50-conversion cap? A: The API returns a 402 error until your monthly quota resets, and no overage charges apply—you simply wait or upgrade.

Calculating Cost Per Conversion for High-Volume Workloads

PDFshift API

For high-volume workloads, calculating cost per conversion with the PDFshift API requires understanding the API’s per-request pricing and your anticipated monthly volume. High-volume cost scaling is achieved by dividing total monthly spend by the number of successful conversions. A clear sequence for this is:

  1. Determine your tiered per-request rate (e.g., $0.004 per file at 100,000+ requests).
  2. Multiply that rate by your projected monthly conversion count.
  3. Add any applicable overage or tier-based fees.
  4. Divide the total cost by the number of expected conversions to get your average unit cost.

This per-conversion figure allows precise budget allocation for automated pipelines.

Solving Real-World Problems: Practical Tips from Frequent Users

To avoid document breakage with PDFshift API, frequent users consistently set a strict timeout interval of 60 seconds in their requests. This prevents hung processes when converting large Excel files or heavy image sets. They also pre-validate all source URLs using a simple headless-browser check, which catches redirect loops or login walls before PDFshift ever processes the job. For recurring batch conversions, savvy users implement a simple retry queue with exponential backoff—PDFshift’s API occasionally throws HTTP 429s under heavy load, and a three-second retry window resolves this reliably. Finally, always specify the real-world troubleshooting parameter landscape=false when scraping report dashboards, as this forces a clean A4 layout without horizontal clipping.

PDFshift API

Optimizing Request Payloads to Reduce Conversion Time

To minimize conversion time, prioritize trimming request payloads to only essential parameters. A bloated payload with unnecessary payload size reduction directly increases processing overhead. First, omit default values like `sandbox: false` or standard page sizes unless overridden. Second, compress inline images or CSS within the payload by using external URLs instead. Even a 10KB reduction can shave seconds off large HTML-to-PDF jobs. Sequence your optimization:

  1. Audit each parameter to confirm it deviates from API defaults.
  2. Replace base64-encoded assets with hosted URLs.
  3. Remove redundant or empty fields before the POST call.

Debugging Common HTTP Errors and Empty Responses

When debugging common HTTP errors and empty responses from the PDFshift API, first verify that your request includes a valid properly encoded HTML source, as malformed input often triggers a 400 status. A 404 error typically indicates an incorrect API endpoint path, while a 500 error suggests temporary server issues—retry with exponential backoff. Empty responses usually stem from network timeouts or missing authentication headers; confirm your API key is transmitted in the Authorization header. Always log both the status code and response body to distinguish between server-side failures and client-side misconfigurations.

  • Check for trailing slashes or typos in the API endpoint URL to avoid 404 errors
  • Inspect response headers for Content-Length zero, which signals an empty body despite a 200 status
  • Validate HTML input against PDFshift’s character limits to prevent truncated or silent failures

Maintaining Clean HTML for Reliable Output Every Time

To ensure reliable output from PDFshift API, regularly validate your HTML structure. Close all tags properly and avoid inline styles that conflict with PDF rendering. Maintaining clean HTML prevents unexpected layout shifts in generated PDFs. Strip unnecessary scripts and unsupported CSS to keep the codebase lean. Use semantic elements rather than generic divs for consistent pagination. Q: How do you troubleshoot a PDFshift output that breaks across pages? A: Check for unclosed

tags or missing width attributes on images, as these commonly disrupt the conversion engine’s parser.