Link Search Menu Expand Document

Add Text to PDF - GoogleAppScript

PDF Add Text, Signatures and Images to PDF sample in GoogleAppScript demonstrating ‘Add Text to PDF’
// Visit Knowledgebase for adding Text Macros to PDF 

// Handle Menu on Google Sheet Open Event
function onOpen() {
  var spreadsheet = SpreadsheetApp.getActive();
  var menuItems = [
    {name: 'CreatePDF', functionName: 'addTextAnnotationToPDF'} 
  spreadsheet.addMenu('', menuItems);
 * A function that adds headers and some initial data to the spreadsheet.
function addTextAnnotationToPDF() {
  var spreadsheet = SpreadsheetApp.getActive();

  // Get 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,
    "annotationsString": `250;20;0-;${imageUrl};24+bold+italic+underline+strikeout;Arial;FF0000;;true`

  // 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
  var pdfCoResponse = UrlFetchApp.fetch('', options);

  var pdfCoRespContent = pdfCoResponse.getContentText();
  var pdfCoRespJson = JSON.parse(pdfCoRespContent);

  // Display Result
} Web API: the Web API with a set of tools for documents manipulation, data conversion, data extraction, splitting and merging of documents. Includes image recognition, built-in OCR, barcode generation and barcode decoders to decode bar codes from scans, pictures and pdf.

Get your API key here!

Download Source Code (.zip)

return to the previous page explore PDF Add Text, Signatures and Images to PDF endpoint