Quickstart
This guide will get you all set up and ready to use the Pdfly API. We'll cover how to get started using one of our API clients and how to make your first API request. We will also look at where to go next to find all the information you need to take full advantage of our powerful REST API.
Before you can make requests to the Pdfly API, you will need to signup and grab your API key from your dashboard. You find it under Settings » API Keys.
Making your first API request
After signing up and getting your API keys from your Pdfly account dashboard, you are ready to make your first call to the Pdfly API. Sample POST requests to the Generate endpoint to generate a PDF of the html posted in the body of your request are shown below.
Replace the API-KEY
value given to x-api-key
in the request headers with the API key you generated on the dashboard to make your request.
You can provide the html to be converted to pdf in the body
property of the request body, or you can provide a url to a webpage in the url
property of the request body.
const axios = require("axios");
const options = {
"method": "POST",
"url": "https://api.pdfly.io/pdf/generate",
"headers": {
"Content-Type": "application/jsons",
"x-api-key": "API-KEY",
},
"data": JSON.stringify({
"body": "HTML",
"url": "https://pdfly.io"
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
API response
{
"pdfUrl": "Url for the generated pdf",
"pdfSizeInBytes": "Size of the generated pdf in bytes"
}
Customizing your PDF
All the parameters for customizing the generated PDF can be added in the same way the body
parameter was used above. Only meta
and layout
parameters are objects, their usage is covered in the section below. For the full list of parameters for customizing your generated PDF check parameters.
Setting PDF metadata and layout
You can set the metadata and layout of the generated PDF, by passing the meta
and layout
properties as shown in the code sample below.
const axios = require("axios");
const options = {
"method": "POST",
"url": "https://api.pdfly.io/pdf/generate",
"headers": {
"Content-Type": "application/jsons",
"x-api-key": "API-KEY",
},
"data": JSON.stringify({
"body": "<html><head><title>Quickstart</title></head><body> <h1>Pdfly API rocks</h1><p>You just generated your first pdf.</p></body></html>",
"layout": {
"format": "A4",
"orientation": "landscape",
"margin_top": "3cm",
"margin_bottom": "3cm",
"margin_left": "3cm",
"margin_right": "3cm"
}
})
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
What's next?
Great, you're now set up with an API client and have made your first request to the API. Here are a few links that might be handy as you venture further into the Pdfly API: