PDFApp
This is a Google Apps Script library for managing PDFs.
Install / Use
/learn @tanaikech/PDFAppREADME
PDFApp
<a name="top"></a> MIT License
<a name="overview"></a>
Overview
This is a Google Apps Script library for managing PDFs.

<a name="description"></a>
Description
Google Apps Script is one of the most powerful tools for cloud computing. When Google Apps Script is used, the result can be obtained even when the user doesn't stay in front of the PC and mobile phone by the triggers. One day, there might be a case where it is required to manage PDF data using Google Apps Script. The combination of Google Docs (Document, Spreadsheet, and Slide) and PDFs is useful for various situations. However, unfortunately, there are no built-in methods for directly managing PDFs using Google Apps Script. Fortunately, it seems that pdf-lib of the Javascript library can be used with Google Apps Script. By this, PDF data can be managed with Google Apps Script using this library. This Google Apps Script library manages PDFs by using it as a wrapper between Google Apps Script and pdf-lib.
I have already published the following posts.
- Exporting Specific Pages From a PDF as a New PDF Using Google Apps Script
- Management of PDF Metadata using Google Apps Script
- Changing Order of Pages in PDF file using Google Apps Script
- Merging Multiple PDF Files as a Single PDF File using Google Apps Script
- Converting All Pages in PDF File to PNG Images using Google Apps Script
- Retrieving and Putting Values for PDF Forms using Google Apps Script
- Creating PDF Forms from Google Slide Template using Google Apps Script
- Embedding Objects in PDF using Google Apps Script
- Add Header and Footer to Exported PDF from Google Spreadsheet using Google Apps Script
- Adding Page Numbers to PDF using Google Apps Script
I created this library to more efficiently manage PDFs with a simple script by summarising the scripts of these posts.
Library's project key
1Xmtr5XXEakVql7N6FqwdCNdpdijsJOxgqH173JSB0UOwdb0GJYJbnJLk
<a name="usage"></a>
Usage
1. Install library
In order to use this library, please install the library as follows.
-
Create a GAS project.
- You can use this library for the GAS project of both the standalone and container-bound script types.
-
- Library's project key is
1Xmtr5XXEakVql7N6FqwdCNdpdijsJOxgqH173JSB0UOwdb0GJYJbnJLk.
- Library's project key is
Scopes
This library uses the following 3 scopes.
https://www.googleapis.com/auth/script.external_requesthttps://www.googleapis.com/auth/drivehttps://www.googleapis.com/auth/presentations
Methods
| Methods | Description | | :-------- | :------------------ | | setPDFBlob | Give the source PDF blob. This method is used with other methods. | | useStandardFont | When you want to use the standard font, please use this method. This method is used with other methods. | | useCustomFont | When you want to use the custom font, please use this method. This method is used with other methods. | ||| | exportPages | Export specific pages from a PDF blob. | | getMetadata | Get PDF metadata from a PDF blob. | | udpateMetadata | Update PDF metadata of a PDF blob. | | reorderPages | Reorder pages of a PDF blob. | | mergePDFs | Merge multiple PDF files in a single PDF. | | convertPDFToPng | Convert PDF pages to PNG images. | | getValuesFromPDFForm | Get values from PDF Form. | | setValuesToPDFForm | Set values to PDF Form. | | createPDFFormBySlideTemplate | Create PDF Form By Google Slide template. | | embedObjects | Embed objects into PDF blob. | | insertHeaderFooter | Add custom header and footer to PDF blob. | | splitPDF | Split each page of a PDF to an individual PDF file. | | addPageNumbers | Add page numbers to PDF. |
<a name="setpdfblob"></a>
setPDFBlob
Give the source PDF blob. This method is used with other methods.
In this sample script, the PDF metadata is retrieved.
const blob = DriveApp.getFileById("###fileId of PDF file###").getBlob();
PDFApp.setPDFBlob(blob).getMetadata()
.then(res => console.log(res))
.catch(err => console.log(err));
<a name="usestandardfont"></a>
useStandardFont
When you want to use the standard font, please use this method. This method is used with other methods.
In this sample script, a value is put into a field of PDF Form with "TimesRoman".
const blob = DriveApp.getFileById("###fileId of PDF file###").getBlob();
const object = {
values: [
{ "name": "textbox.sample1.sample1.page1", "value": "sample update text" }
],
};
PDFApp
.setPDFBlob(blob)
.useStandardFont("TimesRoman")
.setValuesToPDFForm(object)
.then(newBlob => DriveApp.createFile(newBlob))
.catch(err => console.log(err));
<a name="usecustomfont"></a>
useCustomFont
When you want to use the custom font, please use this method. This method is used with other methods.
In this sample script, a value is put into a field of PDF Form with a custom font.
const blob = DriveApp.getFileById("###fileId of PDF file###").getBlob();
const object = {
values: [
{ "name": "textbox.sample1.sample1.page1", "value": "sample update text" }
],
};
PDFApp
.setPDFBlob(blob)
.useCustomFont(DriveApp.getFileById("###fileId of font file###).getBlob())
.setValuesToPDFForm(object)
.then(newBlob => DriveApp.createFile(newBlob))
.catch(err => console.log(err));
<a name="exportpages"></a>
exportPages

Export specific pages from a PDF blob.
const blob = DriveApp.getFileById("###fileId of PDF file###").getBlob();
const pageNumbers = [2, 4, 6, 8];
PDFApp.setPDFBlob(blob).exportPages(pageNumbers)
.then(blob => DriveApp.createFile(blob))
.catch(err => console.log(err));
- In this sample, 2, 4, 6, 8, pages are exported. And, a new PDF file is created to the root folder.
- This is from my post "Exporting Specific Pages From a PDF as a New PDF Using Google Apps Script".
<a name="getmetadata"></a>
getMetadata

Get PDF metadata from a PDF blob.
const blob = DriveApp.getFileById("###fileId of PDF file###").getBlob();
PDFApp.setPDFBlob(blob).getMetadata()
.then(res => console.log(res))
.catch(err => console.log(err));
-
When this script is run, the metadata is retrieved from the inputted PDF blob.
-
When I tested this script, I noticed that the values of
modificationDateandproducermight be a bug in pdf-lib.modificationDatereturns the execution time.produceralways returns pdf-lib (https://github.com/Hopding/pdf-lib). I guessed that this might be a bug in pdf-lib. And, I would like to believe that this will be resolved in the future update. -
This is from my post "Management of PDF Metadata using Google Apps Script".
<a name="udpatemetadata"></a>
udpateMetadata

Update PDF metadata of a PDF blob.
const blob = DriveApp.getFileById("###fileId of PDF file###").getBlob();
const object = {
title: ["sample title", { showInWindowTitleBar: true }], // This property is an array.
subject: "sample subject",
author: "sample author",
creator: "sample creator",
creationDate: new Date("2023-08-01T00:00:00"), // This value is date object.
modificationDate: new Date("2023-08-01T10:00:00"), // This value is date object.
keywords: ["sample keyword 1", "sample keyword 2", "sample keyword 3"], // This property is an array.
producer: "sample producer",
};
PDFApp.setPDFBlob(blob).udpateMetadata(object)
.then(newBlob => DriveApp.createFile(newBlob))
.catch(err => console.log(err));
-
When this script is run, the metadata of "title", "subject", "author", "creator", "creationDate", "modificationDate", "keywords", and "producer" is updated. And, after the update is finished, a new PDF file is created in the root folder.
-
This is from my post "[Management of PDF Metadata using Google Apps Script](https://medium.com/google-cloud/manage
Related Skills
node-connect
347.6kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
summarize
347.6kSummarize or extract text/transcripts from URLs, podcasts, and local files (great fallback for “transcribe this YouTube/video”).
feishu-doc
347.6k|
