About Apps Script

Google Apps Script is a scripting platform designed for rapid application development for the fast and easy creation of business applications that integrate with G Suite products. Modern JavaScript is the scripting language being used to write codes. App Script includes built-in libraries for G Suite applications such as Drive, Calendar, Gmail, and more.

Read more about Apps Script at https://developers.google.com/apps-script

What is PDF.co?

PDF.co is the secure and scalable data extraction API service with a full set of PDF tools included.

Benefits:

  • Reduces spending by using a flexible AI system for data extraction from receipts, invoices, and other documents;
  • Documents and files such as tables, and PDF forms can be read automatically using the Document Parser that is customizable;
  • It possesses functionality that lets the user fill documents with PDF documents, fields to PDF forms, text, and images;
  • It is a potent, unique tool that allows you to combine, split, and delete PDF pages. It also lets you create PDF from advanced HTML;
  • It is perfect for Enterprise clients as they can utilize review logs and API logs;
  • Offline or on-premise versions can be accessed by Premium users;

Security

  • All documents and files processed by PDF.co are encrypted at rest using AES 256-bit encryption;
  • PDF.co relies on TLS and SSL to transmit data and files (the same security protocols that are used by banks)
  • Runs on award-winning secure certified Amazon AWS infrastructure: https://pdf.co/security

Apps Script and PDF.co integration

To start, please use the button below:

Setup Apps Script+PDF.co

How to Merge PDFs

JavaScript Code Snippet (Node.js)

var https = require("https");
var path = require("path");
var fs = require("fs");


// The authentication key (API Key).
// Get your own by registering at https://app.pdf.co/documentation/api
const API_KEY = "***********************************";


// Direct URLs of PDF files to merge
const SourceFiles = [
    "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-merge/sample1.pdf",
    "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-merge/sample2.pdf"
];
// Destination PDF file name
const DestinationFile = "./result.pdf";

// Prepare request to `Merge PDF` API endpoint
var queryPath = `/v1/pdf/merge`;

// JSON payload for api request
var jsonPayload = JSON.stringify({
    name: path.basename(DestinationFile), url: SourceFiles.join(",")
});

var reqOptions = {
    host: "api.pdf.co",
    method: "POST",
    path: queryPath,
    headers: {
        "x-api-key": API_KEY,
        "Content-Type": "application/json",
        "Content-Length": Buffer.byteLength(jsonPayload, '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(jsonPayload);
postRequest.end();

Other PDF Merger API JavaScript sample codes are available here.

Related Pages: