Overview
This is a Google Apps Script library for managing PDFs.

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.
Gists

Abstract
When PDF file can be managed with Google Apps Script, that will lead to the automation process on cloud. In this report, the method for cooking PDF over Google Apps Script.
Introduction
Google Apps Script is one of the strong tools for achieving the automation process. When Google Apps Script can be used for the situation, it can be processed with cloud computing. By this, the users are not required to stay on the desks with the PC. One day, there might be a case where you are required to manage PDF files using Google Apps Script. When PDF files can be managed with Google Apps Script, that will be very important for achieving the automation process. Unfortunately, there are no built-in methods for directly managing PDF data using Google Apps Script. Fortunately, after the V8 runtime has been released, several raw Javascript libraries could be used with Google Apps Script. pdf-lib is also one of them. When this is used, PDF data can be cooked over Google Apps Script. In this report, I would like to introduce achieving this using a Google Apps Script library.
Gists

Description
In this report, I would like to introduce a sample script for efficiently deleting rows by conditions on Google Spreadsheet using Google Apps Script. Recently, I had a situation for being required to achieve this situation. In my report, it has already known that when Sheets API is used, the rows can be efficiently deleted by a condition. Ref However, in that case, Sheets API couldn’t be used. Under this situation, I came up with a method. In this report, I would like to introduce this method.
My report “Easily Managing Time-Driven Triggers Using Google Apps Script” has been featured in “Community Spotlight” of Google Workspace Developer Newsletter on July 2023
https://developers.google.com/workspace/newsletters#expandable-2
Gists

This is a sample script for embedding the objects in PDF using Google Apps Script.
Recently, I had a situation where it is required to manage PDFs using Google Apps Script. At that time, I had a situation where it is required to embed objects of texts and images in PDF using Google Apps Script. So, I created the following Class with Google Apps Script. When this Class is used, the objects of texts and images can embed in PDF.
Gists

This is a sample script for creating PDF forms from a Google Slide template using Google Apps Script.
Recently, I had a situation where it is required to create a custom PDF form. In that case, I thought that when a PDF form can be created from a template, it might be useful. So, I created the following Class with Google Apps Script. When this Class is used, a custom PDF form can be easily created from a Google Slide as a template.
Gists

This is a sample script for retrieving and putting values for PDF Forms using Google Apps Script.
PDF can have the PDF Form for inputting the values in the PDF by the user. Ref Recently, I had a situation that required me to retrieve and put the values to the PDF Form using Google Apps Script. In order to achieve this, I created a Class object with Google Apps Script. That is as follows.
GitHub of OnedriveApp
Gists

This is a sample script for changing the order of pages in a PDF file using Google Apps Script.
Sample script
Before you run this script, please set the variables in the function main.
/**
* ### Description
* Changing order of pages in a PDF file.
*
* @param {Object} fileId is file ID of PDF file. newOrderOfpages is new order of pages. About "ignoreSkippedPages", if this is false, when the PDF has 5 pages and "newOrderOfpages" is "[3, 2]", the exported PDF file has 5 pages of 3, 2, 1, 4, 5. If this is true, when the PDF has 5 pages and "newOrderOfpages" is "[3, 2]", the exported PDF file has only 2 pages of 3 and 2.
* @return {void}
*/
async function changeOrderOfPDFPages_({
fileId,
newOrderOfpages,
ignoreSkippedPages,
}) {
// Load pdf-lib
const cdnjs = "https://cdn.jsdelivr.net/npm/pdf-lib/dist/pdf-lib.min.js";
eval(UrlFetchApp.fetch(cdnjs).getContentText()); // Load pdf-lib
const setTimeout = function (f, t) {
Utilities.sleep(t);
return f();
};
const blob = DriveApp.getFileById(fileId).getBlob();
const pdfData = await PDFLib.PDFDocument.load(
new Uint8Array(blob.getBytes())
);
const numberOfPages = pdfData.getPageCount();
const maxPage = Math.max(...newOrderOfpages);
if (numberOfPages < maxPage || numberOfPages < newOrderOfpages.length) {
throw new Error(
"Maximum page in the order of pages is over than the maximum page of the original PDF file."
);
}
let skippedPages = [];
if (!ignoreSkippedPages && numberOfPages > newOrderOfpages.length) {
skippedPages = [...Array(numberOfPages)]
.map((_, i) => i + 1)
.filter((e) => !newOrderOfpages.includes(e));
}
const pdfDoc = await PDFLib.PDFDocument.create();
const pages = await pdfDoc.copyPages(
pdfData,
[...Array(numberOfPages)].map((_, i) => i)
);
[...newOrderOfpages, ...skippedPages].forEach((e) =>
pdfDoc.addPage(pages[e - 1])
);
const bytes = await pdfDoc.save();
return Utilities.newBlob(
[...new Int8Array(bytes)],
MimeType.PDF,
"sample.pdf"
);
}
function main() {
const fileId = "###"; // Please set a file ID of your a PDF file or a file ID of Google Docs files (Document, Spreadsheet, Slide).
const newOrderOfpages = [3, 1, 2, 5, 4]; // Please set new order of the pages in a PDF file. In this sample, the order of pages of the original PDF file is changed to 3, 1, 2, 5, 4.
const ignoreSkippedPages = false; // If this is false, when the PDF has 5 pages and "newOrderOfpages" is "[3, 2]", the exported PDF file has 5 pages of 3, 2, 1, 4, 5. If this is true, when the PDF has 5 pages and "newOrderOfpages" is "[3, 2]", the exported PDF file has only 2 pages of 3 and 2.
changeOrderOfPDFPages_({ fileId, newOrderOfpages, ignoreSkippedPages }).then(
(blob) => {
DriveApp.createFile(blob.setName("sample.pdf"));
}
);
}
When this script is run, a new PDF file is created with the new order of pages.
GitHub of OnedriveApp