HTML to PDF is a simple tool for converting HTML to PDF. It returns the PDF file generated from the HTML.
npm install @apiverve/htmltopdfshell
npm install @apiverve/htmltopdf
`
Using yarn:
`shell
yarn add @apiverve/htmltopdf
`
---
Configuration
Before using the HTML to PDF API client, you have to setup your account and obtain your API Key.
You can get it by signing up at https://apiverve.com
---
Quick Start
Get started with the Quick Start Guide
The HTML to PDF API documentation is found here: https://docs.apiverve.com/ref/htmltopdf.
You can find parameters, example responses, and status codes documented here.
$3
`javascript
const htmltopdfAPI = require('@apiverve/htmltopdf');
const api = new htmltopdfAPI({
api_key: '[YOUR_API_KEY]'
});
`
---
Usage
---
$3
Using the API is simple. All you have to do is make a request. The API will return a response with the data you requested.
`javascript
var query = {
"marginTop": 0.4,
"marginBottom": 0.4,
"marginLeft": 0.4,
"marginRight": 0.4,
"landscape": false,
"html": " This is the title of the webpage! This is an example paragraph. Anything in the body tag will appear on the page, just like this p tag and its contents.
"
};
api.execute(query, function (error, data) {
if (error) {
return console.error(error);
} else {
console.log(data);
}
});
`
---
$3
You can also use promises to make requests. The API returns a promise that you can use to handle the response.
`javascript
var query = {
"marginTop": 0.4,
"marginBottom": 0.4,
"marginLeft": 0.4,
"marginRight": 0.4,
"landscape": false,
"html": " This is the title of the webpage! This is an example paragraph. Anything in the body tag will appear on the page, just like this p tag and its contents.
"
};
api.execute(query)
.then(data => {
console.log(data);
})
.catch(error => {
console.error(error);
});
`
---
$3
You can also use async/await to make requests. The API returns a promise that you can use to handle the response.
`javascript
async function makeRequest() {
var query = {
"marginTop": 0.4,
"marginBottom": 0.4,
"marginLeft": 0.4,
"marginRight": 0.4,
"landscape": false,
"html": " This is the title of the webpage! This is an example paragraph. Anything in the body tag will appear on the page, just like this p tag and its contents.
"
};
try {
const data = await api.execute(query);
console.log(data);
} catch (error) {
console.error(error);
}
}
`
---
Example Response
`json
{
"status": "ok",
"error": null,
"data": {
"marginLeft": "0.4in",
"marginRight": "0.4in",
"marginTop": "0.4in",
"marginBottom": "0.4in",
"landscape": false,
"pdfName": "79839521-e5b1-4789-b64e-c09e53d8aa87.pdf",
"expires": 1740259885006,
"downloadURL": "https://storage.googleapis.com/apiverve-helpers.appspot.com/htmltopdf/79839521-e5b1-4789-b64e-c09e53d8aa87.pdf?GoogleAccessId=1089020767582-compute%40developer.gserviceaccount.com&Expires=1740259885&Signature=gy9lXWJrXa4Cl3FtQLWezeRWZpf84z3tjxOYd44h2rcRACXBIRtrD%2BzKdIyn1x3vfLtO2rZnKMZx%2Fe%2Bg1Q3EAxPxWkNR9HeNxcKWA3rg45%2FWHjix0C97ud583pNb5OBlcqGmHq%2Fdu6HsEOTfUjSez%2Fml56IrgNsCKfHBWItkmHf%2FABS5u7Ji600tiIKcf2ddpKulkF1%2Fc59mPpwqNbjIbjUua9kjtcMRVAsuYSZ7hZPq1PhAMAbSl7ClPTStIi7dcWHUq%2BjO7rDDcL9l2qXCFuZgMmr0HrTr%2FD0%2BtHjyQP6rzYCldrcV0Ap4t3acQiQXSVnOAUxuGbhi9Mp90z1PGA%3D%3D"
}
}
``