DocRaptor Home

How to Make a PDF or Excel Document

Examples & Agents by Programming Languages > Making Documents with the REST API


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) e.g,
  • The value for the query parameter user_credentials e.g

If you're using our official clients, authentication is included in all examples.

Making a Document

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]


In response to your POST request, we will return one of the below:

HTTP Status Code: 200 - OK

Your request was made successfully, and DocRaptor will return the binary content of the PDF. You should save this binary string to a file or output it directly to the browser.

HTTP Status Code: 400 - Bad Request

This error code means your request can not be completed as expected. Look at the response text for more details on the error. Example errors include: if the download key is not valid, if the requested document has not completed, if there is an error in your generated document, or if there are errors in your HTTP POST request.

HTTP Status Code 401 - Unauthorized

This status code means authorization is required, but has either not been provided or is incorrect. DocRaptor will return this status code if the API key provided is incorrect.

HTTP Status Code: 403 - Forbidden

A 403 status code means the request was made correctly, but the server is refusing to respond. We will return this status code if you do not have permission to view the status of that document, or if you are making too many simultaneous document generation requests.

HTTP Status Code: 422 - Unprocessable Entity

This error means your input document has syntax errors and DocRaptor can not process it at all. Double-check your code and inputs to make sure it is correct.

HTTP Header: X-DocRaptor-Num-Pages

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.