Getting started

The first thing you need is an Auth Key. This is unique to you. You will get it the moment you sign up on PDFRocket.

Before you proceed go ahead and sign up here to get the Auth Key. You will get an Auth Key even on the free plan and the key will allow you access the API 50 times.

Once you have the Auth Key, its time to create a simple page fetcher...

The Simplest Use-Case

The simplest implementation of PDFRocket is by sending a request like this...

curl "" -o example.pdf

The endpoint is essentially the only endpoint you will need to use to access all the features of PDFRocket. Here you pass the Auth Key which you will receive once you sign up and the URL you want to retrieve to the end point and the rendered PDF will be saved as example.pdf.

Some points to note here...
  • The source_url can be HTTP or HTTPS protocol
  • Inline HTML can be passed directly with the source_html parameter. But you will need to use HTTP POST to do that.
  • It's best to url encode the URL value if it contains any variables
  • If the Auth key has expired or if you have run out of your quota, this call will return an error
  • It will also return an error if the page cannot be found.
Sample code
curl "" -o example.pdf
  $ch = curl_init();
  $url = "";
  curl_setopt($ch, CURLOPT_URL,"
  curl_setopt($ch, CURLOPT_HEADER, FALSE);
  $response = curl_exec($ch);


var request = require('request');
var url = '';

    method: 'GET',
    url: '' + url,
    headers: {
      Accept: 'application/json',
  function(error, response, body) {
# importing the requests library 
import requests 
# PDFRocket-endpoint 
URL = ""
# insert your auth key here
auth_key = "xxxyyy"
url = ""
# defining a params dict for the parameters to be sent to the API 
PARAMS = {'auth_key':auth_key, 'url':url} 
# sending get request and saving the response as response object 
r = requests.get(url = URL, params = PARAMS) 
print r.text() 
require 'httparty'

url = ''
query = {
  'auth_key' => 'your auth_key',
  'url' => ''

response = HTTParty.get('', query: query)
results = response.body
puts results


Even though the example above uses simple HTTP GET, and is super useful in certain situations, You will need to use the HTTP POST to access some of the more complex features listed below.

Because of this, we have highlighted all the options where HTTP POST is required.

Document Configuration

Lets look at the options we can exercise to configure the PDF document.

Document Name

To change the default name of the downloaded PDF document, pass the preferred name like this...
&source_url =
&document_name = mydoc.pdf

Set Password

You can optionally set a user level password & a owner level password for your PDFs.

The owner password allows the holder of the password to modify access permissions like copy & edit permissions. The user password only allows access to already specified levels for that user.
&source_url =
&owner_password = byBigPassword
&user_password = mySmallPassword

Inline PDF

When you access PDF Rocket through a GET request through the browser, by default, it will force a download.

If you want to override this and show it inline in the browser itself, set the inline option to 1.
&source_url =
&inline = 1

Accessing Password Protected Websites

If the website you want to render is password protected you can pass the auth_username and the auth_password parameters to let our API access them.
&source_url =
&auth_username = allowed_user
&auth_password = secret


Page Format

PDF Rocket supports various standard page formats. The example below shows you how to set it by using the page_format parameter. If empty, the format defaults to A4.
&source_url =
&page_format = A5

The list of supported formats are...

Letter8.5 x 11
Legal8.5 x 14
Tabloid11 x 17
Ledger17 x 11
A033.1 x 46.8
A123.4 x 33.1
A216.54 x 23.4
A311.7 x 16.54
A48.27 x 11.7
A55.83 x 8.27
A64.13 x 5.83

These are pre-configured page sizes. if you dont find the exact size you want here you can use the technique listed below to set a custom size for your page.

Custom Size

You can set a custom size for the page using page_width and page_height parameter. These will override the page size parameter listed above
&source_url =
&page_width = 1200
&page_height = 800


By default, PDF Rocket defaults to portrait. You can set it to landscape by setting the landcape parameter to true
&source_url =
&landscape = true


By default, no margins are set by PDF Rocket. You can change that by setting margin_left, margin_right, margin_top and margin_bottom parameters as shown below. You will have to specify either px or cm unit types along with the numeric value. Margins also have to be set before setting the header option shown below
&source_url =
&margin_left = 10px
&margin_right = 10px

Headers & Footers

Headers/Footers can be set as normal text or as HTML templates. The templates can be passed by an external url or as inline HTML. Lets explore all the options here

Note: For headers/Footers to work, make sure you have added the appropriate margins.

Plain Text headers/footers

For plain text headers/footers you can set the parameters header_text, header_align, footer_text, footer_align. The headers/footers are center aligned by default
&source_url =
&margin_top = 50px
&header_text = MyHeader
&header_align = right

HTML headers/footers

For HTML headers/footers you can set the parameters header_url or if you want to pass inline HTML, set it to the HTTP POST parameter header_html
&source_url =
&margin_top = 50px
&header_url =

An example of a header code with custom styling would be something like this...
      line-height: 24px;
      font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;
      background-color: #333;color:#fff;
      text-align: center;
      font-size: 15px;
      margin-top: 0px;
      padding-top: 30px;

	<div class='header' >
        Printed on {{date}} from {{url}} - {{pageNumber}} of {{totalPages}}

As you may have noticed in the HTML above, you can use some select variables in them. You can use {{date}}, {{url}}, {{pageNumber}}, {{totalPages}} & {{title}}

Page customizations

lazy loading & wait_after_load

Many websites have images that lazy load. Some load them as the user scrolls down to them. PDF Rocket simulates this behaviour very well. The default wait_after_load is 1000 milliseconds or 1 sec. Pass a value upto 10000 to wait longer on certain image heavy pages. The example below waits for 5 seconds(while automatically scrolling) before rendering the PDF.
&source_url =
&wait_after_load = 5000

Custom CSS Injection

Set the parameter css_url to the URL of a file with custom CSS in it. Just like so...
&source_url =
&css_url =

An example of a css file with custom styling could be something like this...
      background-color: green !important;

Rate Limits & error handling

Rate limits

Here are the API rate limits based on the plan you are on...

PlanRate limit
Free4 requests per minute
Basic25 requests per minute
Pro35 requests per minute
Business45 requests per minute

If you exceed the rate limit, the API will return an rate_limit_exceeded error with the code 402.

Error codes

Here are the different error codes and their meaning. When there is an error, the API returns a "error": "description" string with a description of the error.

Error codeDescription
401Invalid API key
402Rate limit exceeded
403Out of credits
404Resource not found
405Invalid URL
406Bad API call format

Code Examples

Starter PHP code

The function pdfRocket() below can be used to access the full range of options in the API. We have included some examples to get you started easily. Replace the API key with your own to try the code. If you dont have an API key, get one for free in just 2 minutes here

PHP sample code

function pdfRocket($params) {
  $curl = curl_init();

  curl_setopt_array ($curl, array (
      CURLOPT_URL => "",
      CURLOPT_POST => true,
      CURLOPT_POSTFIELDS => json_encode($params),
      CURLOPT_HTTPHEADER => array ('Content-Type:application/json'),

  $response = curl_exec($curl);
  $error = curl_error($curl);
  $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

  if (!empty($error)) {
      throw new Exception($error);
  } elseif ($statusCode >= 400) {
      $body = json_decode($response, true);
      if (isset($body['error'])) {
          throw new Exception($body['error']);
      } else {
          throw new Exception($response);

  return $response;

//Basic Example
$response = pdfRocket(array (
  'auth_key' => 'your_api_key',
  'source_url' => '',

//Example with custom CSS
$response = pdfRocket(array (
  'auth_key' => 'your_api_key',
  'source_url' => '',
  'css_url' => 'https://www.example.commycss.css',

//Example with Inline HTML
$source_html = file_get_contents('invoice.html');
$response = pdfRocket(array (
  'api_key' => 'your_api_key',
  'source_html' => $source_html,
  'margin_left' => '40px',
  'margin_right' => '40px'

//Example with margins
$response = pdfRocket(array (
  'api_key' => 'your_api_key',
  'source_url' => '',
  'margin_left' => '40px',
  'margin_right' => '40px'

//save the pdf file locally
file_put_contents('result.pdf', $response);

//or show the pdf inline 
//echo $response;

Ready to start?

Make use of our 50 free credits to get started risk free