How does it work?

1
User icon

You

Create a template

Create a template

WYSIWYG Editor
Dynamic variables
Page headers & footers
Repeatable table headers
Upload & store images

Instant PDF Templates Editor icon

Instant PDF
Templates Editor

2
App icon

Your App

Get PDFs

Get PDFs

Synchronous REST API call
Supply JSON data for variables
Obtain PDF file within response
No additional CDN needed

Instant PDF REST API icon

Instant PDF
REST API

Create template


Templates are HTML files consisting of static content (text, images, styles,...) and dynamic content (variables). Templates can be created using a WYSIWYG HTML editor. If you require any HTML feature that is not supported by the WYSIWYG editor (borders, background color, repeatable table header,...) it is possible to switch to plain HTML editor. Check out the template "Demo: Hello World".


All the examples mentioned in the documentation can be accessed in our demo. Just log in as demo@instantpdf.eu/demo.



Variables


The key feature of templating is the variables. Placeholders for dynamic content are specified using double curly brackets, as shown above: {{name}}. The value of the variables is specified using JSON as parameters for the template engine. Any valid JSON can be sent to Instant PDF template and the values will be rendered in the resulting file. Example JSON for "Demo: Hello World":


will result in PDF:



Arrays


Instant PDF placeholders can handle arrays. WYSIWYG editor supports arrays inside HTML table. Just specify an array name in the table context menu and use the elements' properties as template variables. Template "Demo: Invoice" demonstrates such a case:

JSON containing array of items sent as parameter:

will result in PDF:



If there is a need to iterate over an array outside of the HTML table, it is necessary to use plain HTML editor and use similar syntax as the WYSIWYG editor did inside table: Simply use tag and around tag you want to iterate (DIV, SPAN, LI,...).



Handlebars


Instant PDF uses Handlebars as the templating engine. If you are interested in a more detailed description with all the features, check out their guide.



Images


Instant PDF offers a small storage dedicated to each account. It is meant to be used for images embedded in the templates. It is possible to upload and use images stored there, or you can you can use any image from your CDN linked via a public URL. The maximum allowed size of an single image is 1MB.





Custom fonts


Instant PDF supports the upload of custom fonts. Custom fonts must be "True Type". Each custom font is included in the generated PDF, increasing the size of the PDF file.



Page headers & footers

Instant PDF supports page headers and footers. It can be defined in the WYSIWYG editor using header/footer folders. There are two variables injected to template from Instant PDF:

  • {{page}} meaning current page number
  • and {{totalPages}} meaning total pages in the whole PDF output.

The size of header/footer is limited to 30% of selected paper size.


The size of header/footer is limited to 30% of selected paper size.



Repeatable table header

If a table extends over a single page, there is option to repeat table header. It is sufficient to use the THEAD tag inside the HTML table. Such a header is used in the template "Demo: invoice", as can be seen in the screenshot below:



PDF generated from the template looks like this:



External content


Instant PDF can handle any external resources accessible via http GET. Moreover, it is possible to pass parameters to such resources. Try "Demo: Voucher" to see how a bar code is generated on-the-fly using barcodeapi.org.

Below, the variable {{voucherId}} is specified in the external URL:

and based on JSON:

such PDF is generated:



Get PDFs


Instant PDF offers REST API for creating PDF documents.

POST https://api.instantpdf.eu/v1/documents/{template-id}

Parameters

Name


Description
X-INSTANT-PDF-API-KEY *required
(http header)
API key connected to your account.
template-id *required
(path parameter)
Unique id of template.
page-size
(query variable)
A0,A1,A2,A3,A5,A6,A7,A8,A9,B0,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,C5E,Comm10E,DLE,Executive,Folio,Ledger,Legal,Letter,Tabloid
Default value : A4
page-orientation
(query variable)
Landscape,Portrait
Default value : Portrait
filename
(query variable)
Filename of generated document
Default value : output.pdf

(request body)
Any JSON structure expected by specified template.
Default value : {}

Responses

Code


Description
200 - Success The template was processed, PDF file was generated and returned.

HTTP Headers
 - Media type : application/pdf
 - Content-Disposition: attachment; filename=specified filename

Response body
 - PDF file
400 - Bad request The template was not processed due to wrong request data.

HTTP Headers
 - X-ERROR-CODE: errorCode
 - X-ERROR-MESSAGE : errorMessage
401 - Unauthorized Invalid API key or template can not be accessed with such API key.
402 - Quota exceeded Monthly quota of PDFs exceeded.
500 - Internal server error Unexpected exception on server side.


Try the template "Demo:Hello World" the way you prefer. Examples below store generated hello.pdf in the current directory.


curl -X POST "https://api.instantpdf.eu/v1/documents/24?page-size=A6&page-orientation=Landscape"
    -H  "accept: application/pdf"
    -H  "X-INSTANT-PDF-API-KEY: 29f99f9f-26b9-43ef-90c7-dacf4b838f6c"
    -H  "Content-Type: application/json"
    -d "{\"name\":\"World\"}"
    -o hello.pdf
<?php // Tested on php 7.4 using extensions "php_curl" and "php_openssl"

// Initialize the cURL session
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cURL, CURLOPT_VERBOSE, true);

// Create a new file for output
$fp = fopen('./hello.pdf', 'w');

//Set URL, headers and parameters
curl_setopt($cURL, CURLOPT_URL, 'https://api.instantpdf.eu/v1/documents/24?page-size=A6&page-orientation=Landscape');
curl_setopt($cURL, CURLOPT_POST, true);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
    'X-INSTANT-PDF-API-KEY: 29f99f9f-26b9-43ef-90c7-dacf4b838f6c',
    'Content-Type: application/json'
    ));
curl_setopt( $cURL, CURLOPT_POSTFIELDS, '{"name":"World"}' );
curl_setopt($cURL, CURLOPT_FILE, $fp);

// Execute the cURL session
curl_exec ($cURL);

// Close cURL session and file
curl_close ($cURL);
fclose($fp);
# Tested on Python 3.11 using module "requests"

import requests

# Initialize the session
session = requests.Session()

# Set URL, headers and parameters
url = 'https://api.instantpdf.eu/v1/documents/24?page-size=A6&page-orientation=Landscape'
headers = {
    'X-INSTANT-PDF-API-KEY': '29f99f9f-26b9-43ef-90c7-dacf4b838f6c',
    'Content-Type': 'application/json'
}
data = '{"name":"World"}'

# Send POST request and save response to file
response = session.post(url, headers=headers, data=data)
with open('./hello.pdf', 'wb') as fp:
    fp.write(response.content)
//tested on Java 1.8

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class Hello {

    public static void main(String[] args) throws IOException {

        //Open Http connection
        URL url = new URL("https://api.instantpdf.eu/v1/documents/24?page-size=A6&page-orientation=Landscape");
        HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();

        //Set headers and parameters
        httpConn.setRequestMethod("POST");
        httpConn.setRequestProperty("Accept", "application/pdf");
        httpConn.setRequestProperty("Content-type", "application/json");
        httpConn.setRequestProperty("X-INSTANT-PDF-API-KEY", "29f99f9f-26b9-43ef-90c7-dacf4b838f6c");
        httpConn.setDoOutput(true);
        OutputStream os = httpConn.getOutputStream();
        byte[] json = "{\"name\":\"World\"}".getBytes("utf-8");
        os.write(json, 0, json.length);

        //write response to file and close connection
        InputStream inputStream = httpConn.getInputStream();
        FileUtils.copyInputStreamToFile(inputStream, new File("hello.pdf"));
        httpConn.disconnect();
    }
}

API key


Instant PDF creates your personal API key during registration process. The Api key is visible on Profile page.



Template id


Template id is generated by the system. It is visible on the Template list page.