How to generate PDF invoice from HTML template (node for HTML to PDF API in JavaScript with Web API

See how to generate PDF invoice from HTML template (node to have HTML to PDF API in JavaScript

Here you may find thousands pre-made source code pieces for easy implementation in your own programming projects. Web API helps with HTML to PDF API in JavaScript. Web API is the Rest API that provides set of data extraction functions, tools for documents manipulation, splitting and merging of pdf files. Includes built-in OCR, images recognition, can generate and read barcodes from images, scans and pdf.

The SDK samples like this one below explain how to quickly make your application do HTML to PDF API in JavaScript with the help of Web API. This JavaScript sample code should be copied and pasted into your project. After doing this just compile your project and click Run. Test JavaScript sample code examples whether they respond your needs and requirements for the project.

ByteScout free trial version is available for FREE download from our website. Programming tutorials along with source code samples are included.

Try Web API today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)

var https = require("https"); var path = require("path"); var fs = require("fs"); // The authentication key (API Key). // Get your own by registering at const API_KEY = "***********************************"; // HTML template const template = "./invoice_template.html"; // Data to fill the template const templateData = "./invoice_data.json"; // Destination PDF file name const DestinationFile = "./result.pdf"; // Prepare request to `HTML To PDF` API endpoint var queryPath = `/v1/pdf/convert/from/html?name=${path.basename(DestinationFile)}`; var reqOptions = { host: "", path: encodeURI(queryPath), method: "POST", headers: { "x-api-key": API_KEY, "Content-Type": "application/json" } }; var requestBody = JSON.stringify({ "html": fs.readFileSync(template, "utf8"), "templateData": fs.readFileSync(templateData, "utf8") }); // Send request var postRequest = https.request(reqOptions, (response) => { response.on("data", (d) => { // Parse JSON response var data = JSON.parse(d); if (data.error == false) { // Download PDF file var file = fs.createWriteStream(DestinationFile); https.get(data.url, (response2) => { response2.pipe(file) .on("close", () => { console.log(`Generated PDF file saved as "${DestinationFile}" file.`); }); }); } else { // Service reported error console.log(data.message); } }); }).on("error", (e) => { // Request error console.log(e); }); // Write request data postRequest.write(requestBody); postRequest.end();

Try Web API today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)



Get 60 Day Free Trial or Visit Web API Home Page

Explore Web API Documentation

Get Web API Free Training


Get Your Free API Key

Explore Web API Documentation

Related Samples: