- Getting Started
- Installation
- Key Concepts
- Integrations
- Account & Billing
- Security & Privacy
- PDF Generation
- Reference
- Tutorials
- Troubleshooting
- Excel Generation
- Reference
- Troubleshooting
API Overview
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.
Authentication
If you're using our official clients, authentication is included in all examples. To integrate directly with our REST API, you'll need to authenticate with your API key, which can be found on your account account dashboard. We support two authentication methods:
HTTP Basic Authentication (preferred)
For HTTP Basic Authentication, use a blank password and your API key as the username. If you're unfamiliar with basic authentication, please carefully review the aforelinked Wikipedia article or look for a code example in your programming language. The credentials must be formatted precisely and then Base64 encoded (ie, Base64.encode("YOUR_API_KEY_HERE:")
).
Query Parameter Authentication
Use the GET parameter user_credentials
with your API key as the value.
Making a Document
To make documents, POST
to https://staging-api.docraptor.com/docs
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]
API Response
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"?>
<errors>
<error>Error downloading document content from supplied url.</error>
</errors>
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.