Introduction Last updated: 2021-09-27

Welcome to pdf generator, a tool to convert different types of documents to pdf. To convert documents to PDF you can either use our built-in file uploaders or our sophisticated API endpoints for professional use. Our API points come with several options for optimal outcome which will be listed below. You can start for free right now with up to 500 free API calls. You can either read this documentation experiment with the postman documentation

Authentication

To successfully make a request you need to specify your token. You can generate the token on your dashboard > api keys

Header: X-PDFOnline-ApiKey <api-key> apiToken
Header: X-PDFOnline-ApiKey apiToken

APIs

Provide a public URL to convert your html fast and securely to PDF.

Html to pdf

Http request
POST https://pdf-generator.online/api/convert/html/pdf

Request parameters
Parameter Type Description Example
file_url string* (required) The url that will be converted to html http://acme.com/
save 0|1 Should the document be hosted on pdf-generator? default: 0
partner number Selected partner will own the file (Partner ID) 15
scale number The zoom that should used default: 0.77
waitUntil Type: waitUntil Differentiates the way that the document is loaded. Different configuration results in different download times. default: load
format Type: format Creates different width and height ration default: A4
marginTop number the margin that it should have from the top in cm default: 0.3
marginBottom number the margin that it should have from the bottom in cm default: 0.2
marginLeft number the margin that it should have from the left in cm default: 0.2
marginRight number the margin that it should have from the right in cm default: 0.2

Return type

remember Return types are different depending on if we save the document or not

if the document is saved:

the document code is returned which can be used to get the file later on with our other endpoints


							  {"code": "906ccede-b956-4609-82b6-f87ae6ccedd3"}
							
if the document isn't saved binary data is returned

Types
Type: WaitUntil
Parameter description
load consider navigation to be finished when the load event is fired.
domcontentloaded consider navigation to be finished when the DOMContentLoaded event is fired
networkidle0 consider navigation to be finished when there are no more than 0 network connections for at least 500 ms
networkidle2 consider navigation to be finished when there are no more than 2 network connections for at least 500 ms
Type: format
Parameter description
Letter 8.5in x 11in
Legal 8.5in x 14in
Tabloid 11in x 17in
Ledger 17in x 11in
A0 33.1in x 46.8in
A1 23.4in x 33.1in
A2 16.54in x 23.4in
A3 11.7in x 16.54in
A4 8.27in x 11.7in
A5 5.83in x 8.27in
A6 4.13in x 5.83in
Code examples

	<?php

	$curl = curl_init();

	curl_setopt_array($curl, array(
		CURLOPT_URL => 'https://pdf-generator.online/api/convert/html/pdf',
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_ENCODING => '',
		CURLOPT_MAXREDIRS => 10,
		CURLOPT_TIMEOUT => 0,
		CURLOPT_FOLLOWLOCATION => true,
		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		CURLOPT_CUSTOMREQUEST => 'POST',
		CURLOPT_POSTFIELDS =>'{
		"file_url": "http://acme.com/",
		"scale": 1,
		"waitUntil": "load"
	}',
		CURLOPT_HTTPHEADER => array(
		'Content-Type: application/json',
		'X-PDFOnline-ApiKey: apiToken'
		),
	));

	$response = curl_exec($curl);

	curl_close($curl);
	file_put_contents('output.pdf', $response);
									
											

	curl --location --request POST 'https://pdf-generator.online/api/convert/html/pdf' \
	--header 'Content-Type: application/json' \
	--header 'X-PDFOnline-ApiKey: apiToken' \
	--data-raw '{
		"file_url": "http://acme.com/",
		"scale": 1,
		"waitUntil": "load"
	}' --output output.pdf
							

	Unirest.setTimeouts(0, 0);
	File response = Unirest.post("https://pdf-generator.online/api/convert/html")
		.header("Content-Type", "application/json")
		.header("X-PDFOnline-ApiKey", "c0f8a4efca-3d8a7d9e5f-c69c9ef3b6-dae10b77dd")
		.body("{\n    \"file_url\": \"https://acme.com\",\n    \"save\": \"0\"\n}")
		.getBody();
								  
												
											
          
	var myHeaders = new Headers();
	myHeaders.append("Content-Type", "application/json");
	myHeaders.append("X-PDFOnline-ApiKey", "apiToken");

	var raw = "{\n    \"file_url\": \"http://acme.com/\",\n    \"scale\": 1,\n    \"waitUntil\": \"load\",\n}";

	var requestOptions = {
	method: 'POST',
	headers: myHeaders,
	body: raw,
	redirect: 'follow'
	};

	fetch("https://pdf-generator.online/api/convert/html/pdf", requestOptions)
	.then(response => response.blob())
	.then(result => {
		var blob = new Blob([result], {type: "application/pdf"});
		var link=document.createElement('a');
		link.href=window.URL.createObjectURL(blob);
		link.download="myFileName.pdf";
		link.click();
	})
	.catch(error => console.log('error', error));
										

Upload files

You can upload any file type to our server and use them later for whatever suits your needs! Authentication works as usual using the authentication header.

Http request
POST https://pdf-generator.online/api/file
Request parameters
Parameter Type Description Example
file file *(required) The file to be uploaded
filename string The name of your file Something useful
partner array An array of partners who will have access to this file [11,23,44]
Return type: JSON

	{"code": "906ccede-b956-4609-82b6-f87ae6ccedd3"}
						

Download hosted documents

Downloading hosted files consumes 1 api request per download. To download a file you will need the file code and your api token

Http request
GET https://pdf-generator.online/api/file/<doc-code>?token=<public-token>

Convert other document types to pdf

Http request
POST https://pdf-generator.online/api/convert/pdf

Request parameters
Parameter Type Description Example
doc local file* (required) The document that will be used to be transformed to pdf
save 0|1 Should the document be hosted on pdf-generator? default: 0
partner number Selected partner will own the file (Partner ID) 15
filename string A name for your file document number 44 | mr. Elliot

Return type

remember Return types are different depending on if we save the document or not

if the document is saved:

the document code is returned which can be used to get the file later on with our other endpoints


 	{"code": "906ccede-b956-4609-82b6-f87ae6ccedd3"}
                    
if the document isn't saved binary data is returned

	<?php

	$curl = curl_init();
	
	curl_setopt_array($curl, array(
		CURLOPT_URL => 'https://pdf-generator.online/api/convert/pdf',
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_ENCODING => '',
		CURLOPT_MAXREDIRS => 10,
		CURLOPT_TIMEOUT => 0,
		CURLOPT_FOLLOWLOCATION => true,
		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		CURLOPT_CUSTOMREQUEST => 'POST',
		CURLOPT_POSTFIELDS => array('save' => '0','doc'=> new CURLFILE('PATH_TO_FILE'),'filename' => 'Basic Authoring And Testing'),
		CURLOPT_HTTPHEADER => array(
		'X-PDFOnline-ApiKey: apiToken'
		),
	));
	
	$response = curl_exec($curl);
	
	curl_close($curl);
	file_put_contents('output.pdf', $response);
			
								

	curl --location --request POST 'https://pdf-generator.online/api/convert/pdf' \
	--header 'X-PDFOnline-ApiKey: apiToken' \
	--form 'save="0"' \
	--form 'doc=@"PATH_TO_FILE"' \
	--form 'filename="Basic Authoring And Testing"' \
	--output output.pdf
				

	Unirest.setTimeouts(0, 0);
	File result = Unirest.post("https://pdf-generator.online/api/convert/pdf")
		.header("X-PDFOnline-ApiKey", "apiToken")
		.field("save", "0")
		.field("file", new File(FILE_PATH))
		.field("filename", "Basic Authoring And Testing")
		.getBody();
									
								
          
	var myHeaders = new Headers();
	myHeaders.append("X-PDFOnline-ApiKey", "apiToken");
	
	// fileInput.files[0] will be the file inside an input
	var formdata = new FormData();
	formdata.append("save", "0");
	formdata.append("doc", fileInput.files[0], "biography.docx");
	formdata.append("filename", "Basic Authoring And Testing");
	
	var requestOptions = {
		method: 'POST',
		headers: myHeaders,
		body: formdata,
		redirect: 'follow'
	};
	
	// Download the file
	fetch("https://pdf-generator.online/api/convert/pdf", requestOptions)
		.then(response => response.blob())
		.then(result => {
			var blob = new Blob([result], {type: "application/pdf"});
			var link=document.createElement('a');
			link.href=window.URL.createObjectURL(blob);
			link.download="myFileName.pdf";
			link.click();
		})
		.catch(error => console.log('error', error));
							

Partners

partners are entities that can view files that you upload and download them. Download of files are restricted with a special key.

Operations

Add partner

POST https://pdf-generator.online/api/partner

Request parameters
Parameter Type Description Example
name *(required) string *(required) Name of the partner John
surname *(required) string *(required) Surname of the partner Doe
email *(required) string *(required) Email of the partner johndoe@gmail.com
Return type

	{"id": "10"}
						

	<?php

	$curl = curl_init();

	curl_setopt_array($curl, array(
		CURLOPT_URL => 'https://pdf-generator.online/api/partner',
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_ENCODING => '',
		CURLOPT_MAXREDIRS => 10,
		CURLOPT_TIMEOUT => 0,
		CURLOPT_FOLLOWLOCATION => true,
		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		CURLOPT_CUSTOMREQUEST => 'POST',
		CURLOPT_POSTFIELDS => array('name' => 'joe','surname' => 'doe','email' => 'johndoe@gmail.com'),
		CURLOPT_HTTPHEADER => array(
		'X-PDFOnline-ApiKey: apiToken',
		'Content-Type: application/json'
		),
	));
	
	$response = curl_exec($curl);
	
	curl_close($curl);
	echo $response;
				
									

	curl --location --request POST 'https://pdf-generator.online/api/partner' \
	--header 'X-PDFOnline-ApiKey: apiToken' \
	--header 'Content-Type: application/json' \
	--form 'name="john"' \
	--form 'surname="doe"' \
	--form 'email="johndoe@gmail.com"'
					

	Unirest.setTimeouts(0, 0);
	HttpResponse response = Unirest.post("https://pdf-generator.online/api/partner")
		.header("X-PDFOnline-ApiKey", "apiToken")
		.header("Content-Type", "application/json")
		.multiPartContent()
		.field("name", "john")
		.field("surname", "doe")
		.field("email", "johndoe@gmail.com")
		.asString();						
								
          
	var myHeaders = new Headers();
	myHeaders.append("X-PDFOnline-ApiKey", "apiToken");
	myHeaders.append("Content-Type", "application/json");
	
	var formdata = new FormData();
	formdata.append("name", "john");
	formdata.append("surname", "doe");
	formdata.append("email", "johndoe@gmail.com");
	
	var requestOptions = {
		method: 'POST',
		headers: myHeaders,
		body: formdata,
		redirect: 'follow'
	};
	
	fetch("https://pdf-generator.online/api/partner", requestOptions)
		.then(response => response.text())
		.then(result => console.log(result))
		.catch(error => console.log('error', error));
								

Edit partner

PUT https://pdf-generator.online/api/partner/:id

Request parameters
Parameter Type Description Example
name string Name of the partner John
surname string Surname of the partner Doe
email string Email of the partner johndoe@gmail.com
Return type

	{"name": "john", "surname": "doe", "email": "johndoe@gmail.com", "token": "aXee43ab-XXXX-XXXX-b9e9-XXX6bea5a0XX"}
					

	<?php

	$curl = curl_init();

	curl_setopt_array($curl, array(
		CURLOPT_URL => 'https://pdf-generator.online/api/partner',
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_ENCODING => '',
		CURLOPT_MAXREDIRS => 10,
		CURLOPT_TIMEOUT => 0,
		CURLOPT_FOLLOWLOCATION => true,
		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		CURLOPT_CUSTOMREQUEST => 'PUT',
		CURLOPT_POSTFIELDS => array('name' => 'joe','surname' => 'doe','email' => 'johndoe@gmail.com'),
		CURLOPT_HTTPHEADER => array(
		'X-PDFOnline-ApiKey: apiToken',
		'Content-Type: application/json'
		),
	));

	$response = curl_exec($curl);

	curl_close($curl);
	echo $response;
			
								

	curl --location --request PUT 'https://pdf-generator.online/api/partner' \
	--header 'X-PDFOnline-ApiKey: apiToken' \
	--header 'Content-Type: application/json' \
	--form 'name="john"' \
	--form 'surname="doe"' \
	--form 'email="johndoe@gmail.com"'
				

	Unirest.setTimeouts(0, 0);
	HttpResponse response = Unirest.put("https://pdf-generator.online/api/partner")
		.header("X-PDFOnline-ApiKey", "apiToken")
		.header("Content-Type", "application/json")
		.multiPartContent()
		.field("name", "john")
		.field("surname", "doe")
		.field("email", "johndoe@gmail.com")
		.asString();						
							
          
	var myHeaders = new Headers();
	myHeaders.append("X-PDFOnline-ApiKey", "apiToken");
	myHeaders.append("Content-Type", "application/json");

	var formdata = new FormData();
	formdata.append("name", "john");
	formdata.append("surname", "doe");
	formdata.append("email", "johndoe@gmail.com");

	var requestOptions = {
		method: 'PUT',
		headers: myHeaders,
		body: formdata,
		redirect: 'follow'
	};

	fetch("https://pdf-generator.online/api/partner", requestOptions)
		.then(response => response.text())
		.then(result => console.log(result))
		.catch(error => console.log('error', error));
							

Delete partner

DELETE https://pdf-generator.online/api/partner/:id

Get partner

GET https://pdf-generator.online/api/partner/:id

Return type

	{"name": "john", "surname": "doe", "email": "johndoe@gmail.com"}
					

Templates

Templates are a very useful type of html file that can be used together with parameters to generate a PDF file. Remember, templates are just HTML + DATA = PDF. Our underlying engine uses Mustache to insert the parameters to the html file. You find usage instructions in the following page

Operations

POST https://pdf-generator.online/api/template
Request parameters
Parameter Type Description Example
html (*required) file The html file including the parameters
title (*required) string The title of the template Invoice Generator #1
Return type

	{"id": 20}
					

	<?php

	$curl = curl_init();
	
	curl_setopt_array($curl, array(
	  CURLOPT_URL => 'https://pdf-generator.online/api/template',
	  CURLOPT_RETURNTRANSFER => true,
	  CURLOPT_ENCODING => '',
	  CURLOPT_MAXREDIRS => 10,
	  CURLOPT_TIMEOUT => 0,
	  CURLOPT_FOLLOWLOCATION => true,
	  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	  CURLOPT_CUSTOMREQUEST => 'POST',
	  CURLOPT_POSTFIELDS => array('html'=> new CURLFILE('PATH_TO_FILE'), 'title' => 'Some title'),
	  CURLOPT_HTTPHEADER => array(
		'X-PDFOnline-ApiKey' => 'apiToken'
	  ),
	));
	
	$response = curl_exec($curl);
	
	curl_close($curl);
	echo $response;
			
								

	curl --location --request POST 'https://pdf-generator.online/api/template' \
	--header 'X-PDFOnline-ApiKey: apiToken' \
	--form 'html=@"PATH_TO_FILE"'
				

	Unirest.setTimeouts(0, 0);
	HttpResponse response = Unirest.post("https://pdf-generator.online/api/template")
		.header("X-PDFOnline-ApiKey", "apiToken")
		.field("file", new File("PATH_TO_FILE"))
		.asString();				
							
          
	var data = new FormData();
	data.append("html", fileInput.files[0], "newfile2.html");
		
	var xhr = new XMLHttpRequest();
	xhr.withCredentials = true;
	
	xhr.addEventListener("readystatechange", function() {
		if(this.readyState === 4) {
		console.log(this.responseText);
		}
	});
	
	xhr.open("POST", "https://pdf-generator.online/api/template");
	xhr.setRequestHeader("X-PDFOnline-ApiKey", "apiToken");
	
	xhr.send(data);
							

Get template

GET https://pdf-generator.online/api/template/:id
Return type

	{
		"id": 38,
		"idusr": 56,
		"filename": "36b6e1d2-e229-4c51-9551-246810d48d58.html",
		"template": null,
		"title": "New template",
		"recstamp": "2021-10-15T07:46:07.000Z"
	}
						

Convert template

Join data with the template to create a pdf
POST https://pdf-generator.online/api/template/convert
Request parameters
Parameter Type Description Example
templateId (*required) integer The id of the template that will be used
parameters (*required) object An object that will fill the parameters of the template

	
{
	"total": "312.00",
	"receipt": {
		"date": "Jul 09, 2014 - 12:20 pm",
		"number":"434334343"
	},
	"username": "Thanasis Mpalatsoukas",
	"items": [
		{
		"name": "Html theme",
		"quantity": "3",
			"amount": 60
		}
	],
	"subtotal": "320",
}
	
									  

Add watermark to pdf

To add a watermark to your pdfs all you need is 2 locally stored pdf files. One will work as a watermark and the other one as the pdf which will include the watermark
Request parameters
Parameter Type Description Example
watermark file The watermark that will be included
front file The pdf that will have the watermark added
Return type: binary

	<?php

	$curl = curl_init();
	
	curl_setopt_array($curl, array(
	  CURLOPT_URL => 'https://pdf-generator.online/apiTest/pdf/watermark',
	  CURLOPT_RETURNTRANSFER => true,
	  CURLOPT_ENCODING => '',
	  CURLOPT_MAXREDIRS => 10,
	  CURLOPT_TIMEOUT => 0,
	  CURLOPT_FOLLOWLOCATION => true,
	  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	  CURLOPT_CUSTOMREQUEST => 'POST',
	  CURLOPT_POSTFIELDS => array('watermark'=> new CURLFILE('PATH_TO_FILE_1'),'front'=> new CURLFILE('PATH_TO_FILE_2')),
	  CURLOPT_HTTPHEADER => array(
		'X-PDFOnline-ApiKey: apiToken'
	  ),
	));
	
	$response = curl_exec($curl);
	
	curl_close($curl);
	file_put_contents("output.pdf", $response);
			
									

	curl --location --request POST 'https://pdf-generator.online/apiTest/pdf/watermark' \
	--header 'X-PDFOnline-ApiKey: 75d777ed8f-8a69806fd3-27b30c663a-0ccf0137e3' \
	--form 'watermark=@"FILE_PATH_1"' \
	--form 'front=@"FILE_PATH_2"' --output output.pdf
					

	File response = Unirest.post("https://pdf-generator.online/apiTest/pdf/watermark")
		.header("X-PDFOnline-ApiKey", "apiToken")
		.field("file", new File("PATH_TO_FILE_1"))
		.field("file", new File("PATH_TO_FILE_2"))
		.asString();
										
								
          
	var data = new FormData();
	data.append("watermark", fileInput.files[0], "background.pdf");
		data.append("front", fileInput.files[0], "main.pdf");
		
	var xhr = new XMLHttpRequest();
	xhr.withCredentials = true;
	
	xhr.addEventListener("readystatechange", function() {
		if(this.readyState === 4) {
			var blob = new Blob([result], {type: "application/pdf"});
			var link=document.createElement('a');
			link.href=window.URL.createObjectURL(blob);
			link.download="myFileName.pdf";
			link.click();
		}
	});
	
	xhr.open("POST", "https://pdf-generator.online/apiTest/pdf/watermark");
	xhr.setRequestHeader("X-PDFOnline-ApiKey", "apiToken");
	
	xhr.send(data);