ByteScout Cloud API Server - HTML To PDF API - JavaScript - Generate PDF Invoice From HTML Template (Node.js) - ByteScout

ByteScout Cloud API Server – HTML To PDF API – JavaScript – Generate PDF Invoice From HTML Template (Node.js)

  • Home
  • /
  • Articles
  • /
  • ByteScout Cloud API Server – HTML To PDF API – JavaScript – Generate PDF Invoice From HTML Template (Node.js)

How to generate PDF invoice from HTML template (node for HTML to PDF API in JavaScript with ByteScout Cloud API Server

How to generate PDF invoice from HTML template (node in JavaScript with easy ByteScout code samples to make HTML to PDF API. Step-by-step tutorial

Quick guide:Learn how to generate PDF invoice from HTML template (node in JavaScript. ByteScout Cloud API Server helps with HTML to PDF API in JavaScript. ByteScout Cloud API Server is API server that is ready to use and can be installed and deployed in less than 30 minutes on your own Windows server or server in a cloud. It can save data and files on your local server-based file storage or in Amazon AWS S3 storage. Data is processed solely on the API server and is powered by ByteScout engine, no cloud services or Internet connection is required for data processing..

Use the code displayed below in your application to save a lot of time on writing and testing code. This JavaScript sample code can be used by copying and pasting into your project. Once done,just compile your project and click Run. Enjoy writing a code with ready-to-use sample JavaScript codes to implement HTML to PDF API using ByteScout Cloud API Server.

Our website provides free trial version of ByteScout Cloud API Server that gives source code samples to assist with your JavaScript project.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

app.js
      
// Please NOTE: In this sample we're assuming Cloud Api Server is hosted at "https://localhost". // If it's not then please replace this with with your hosting url. var https = require("https"); var path = require("path"); var fs = require("fs"); // 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 = `/pdf/convert/from/html?name=${path.basename(DestinationFile)}`; var reqOptions = { host: "localhost", path: encodeURI(queryPath), method: "POST", headers: { "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();

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Cloud API Server Home Page

Explore ByteScout Cloud API Server Documentation

Explore Samples

Sign Up for ByteScout Cloud API Server Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

invoice_data.json
      
{ "number": "1234567", "date": "April 30, 2016", "from": "Acme Inc., City, Street 3rd , +1 888 123-456, support@example.com", "to": "Food Delivery Inc., New York, Some Street, 42", "lines": [{ "title": "Setting up new web-site", "quantity": 3, "price": 50 }, { "title": "Configuring mail server and mailboxes", "quantity": 5, "price": 50 }] }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Cloud API Server Home Page

Explore ByteScout Cloud API Server Documentation

Explore Samples

Sign Up for ByteScout Cloud API Server Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

package.json
      
{ "name": "test", "version": "1.0.0", "description": "PDF.co", "main": "app.js", "scripts": { }, "keywords": [ "pdf.co", "web", "api", "bytescout", "api" ], "author": "ByteScout & PDF.co", "license": "ISC", "dependencies": { "request": "^2.88.2" } }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Cloud API Server Home Page

Explore ByteScout Cloud API Server Documentation

Explore Samples

Sign Up for ByteScout Cloud API Server Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Cloud API Server Home Page

Explore ByteScout Cloud API Server Documentation

Explore Samples

Sign Up for ByteScout Cloud API Server Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next