DocRaptor Home

API Overview

How to authenticate with DocRaptor and make documents

Converting HTML into PDF and XLS documents is fast and painless with DocRaptor. Learn how to authenticate with DocRaptor and make a document below, or check out a code example in your language.

You'll authenticate with your API key, which can be found on your account dashboard. You can use your API key in one of two ways:

  • The username for HTTP Basic Authentication (preferred)
  • The value for the query parameter user_credentials

If you're using our official clients, authentication is included in all examples. If you are writing your own client, per RFC 2617 basic auth credentials need to be base64-encoded.

To make documents, POST to with JSON. Only a few options are required and most have reasonable defaults. Here are the minimum options for making a PDF:

  "type": "pdf",
  "document_content": "<html><body>Hello World!</body></html>"

Some options are nested and are referred to like prince[media] in the documentation. As JSON they should look like this:

  "type": "pdf",
  "document_content": "<html><body>Hello World!</body></html>",
  "prince_options": {
    "media": "screen"

JSON is preferred, but you can also send form encoded variables by wrapping the option with doc[] and adding another [] for sub options.

type becomes doc[type]
prince_options[screen] becomes doc[prince_options][screen]

If successful, the POST call returns a binary string containing your PDF. Save this string as a file on your server or send it directly to the browser for the user to download. Alternatively, instead of a binary string, hosted documents return a public URL while asynchronously generated documents return a status_id used to retrieve the document.

If an error occurs while generating your document, an XML error message will be returned instead of the binary string:

<?xml version="1.0" encoding="UTF-8"?>
  <error>Error downloading document content from supplied url.</error>

The HTTP status code returned can be used to determine generation success or failure.

For PDF documents, the X-DocRaptor-Num-Pages response header will contain the number of pages contained in the document.

Ready to get started? Try DocRaptor for free with unlimited test documents.