How to add text and images to PDF in GoogleAppScript with PDF.co Web API

PDF.co Web API: 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.

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

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

program.gs

      
// Handle PDF.co Menu on Google Sheet Open Event function onOpen() { var spreadsheet = SpreadsheetApp.getActive(); var menuItems = [ {name: 'CreatePDF', functionName: 'addImageToPDF'} ]; spreadsheet.addMenu('PDF.co', menuItems); } /** * A function that adds headers and some initial data to the spreadsheet. */ function addImageToPDF() { var spreadsheet = SpreadsheetApp.getActive(); // Get PDF.co API Key Cell let pdfCoAPIKeyCell = spreadsheet.getRange("B1"); // Get Cells for Input/Output let pdfUrlCell = spreadsheet.getRange("A4"); let imageUrlCell = spreadsheet.getRange("B4"); let resultUrlCell = spreadsheet.getRange("C4"); let pdfCoAPIKey = pdfCoAPIKeyCell.getValue(); let pdfUrl = pdfUrlCell.getValue(); let imageUrl = imageUrlCell.getValue(); // Prepare Payload var data = { "async": false, "encrypt": false, "inline": true, "name": "sample_result", "url": pdfUrl, "imagesString": `260;350;0-;${imageUrl}` }; // Prepare Request Options var options = { 'method' : 'post', 'contentType': 'application/json', 'headers': { "x-api-key": pdfCoAPIKey }, // Convert the JavaScript object to a JSON string. 'payload' : JSON.stringify(data) }; // Get Response // https://developers.google.com/apps-script/reference/url-fetch var pdfCoResponse = UrlFetchApp.fetch('https://api.pdf.co/v1/pdf/edit/add', options); var pdfCoRespContent = pdfCoResponse.getContentText(); var pdfCoRespJson = JSON.parse(pdfCoRespContent); // Display Result if(!pdfCoRespJson.error){ resultUrlCell.setValue(pdfCoRespJson.url); } else{ resultUrlCell.setValue(pdfCoRespJson.message); } }

VIDEO

ON-PREMISE OFFLINE SDK

Get 60 Day Free Trial

See also:

ON-DEMAND REST WEB API

Get Your API Key

See also:

Related Samples: