{"id":13433197,"url":"https://github.com/tanaikech/PDFApp","last_synced_at":"2025-03-17T10:33:40.254Z","repository":{"id":188856557,"uuid":"679557058","full_name":"tanaikech/PDFApp","owner":"tanaikech","description":"This is a Google Apps Script library for managing PDFs.","archived":false,"fork":false,"pushed_at":"2024-05-17T06:41:27.000Z","size":1187,"stargazers_count":34,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-01T02:32:43.662Z","etag":null,"topics":["gas","gas-library","google-apps-script","google-apps-script-library","googleappsscript","library","pdf","pdf-forms","pdf-generation","pdf-management","pdf-manager"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tanaikech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-08-17T05:38:17.000Z","updated_at":"2024-07-10T05:11:40.000Z","dependencies_parsed_at":"2023-11-26T07:25:29.625Z","dependency_job_id":"3c597340-495a-4703-8ca9-47bd2000e039","html_url":"https://github.com/tanaikech/PDFApp","commit_stats":null,"previous_names":["tanaikech/pdfapp"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2FPDFApp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2FPDFApp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2FPDFApp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanaikech%2FPDFApp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tanaikech","download_url":"https://codeload.github.com/tanaikech/PDFApp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221675298,"owners_count":16861860,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gas","gas-library","google-apps-script","google-apps-script-library","googleappsscript","library","pdf","pdf-forms","pdf-generation","pdf-management","pdf-manager"],"created_at":"2024-07-31T02:01:22.314Z","updated_at":"2024-10-27T12:32:22.616Z","avatar_url":"https://github.com/tanaikech.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# PDFApp\n\n\u003ca name=\"top\"\u003e\u003c/a\u003e\n[MIT License](LICENCE)\n\n\u003ca name=\"overview\"\u003e\u003c/a\u003e\n\n# Overview\n\nThis is a Google Apps Script library for managing PDFs.\n\n![](images/fig1.png)\n\n\u003ca name=\"description\"\u003e\u003c/a\u003e\n\n# Description\n\nGoogle 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](https://pdf-lib.js.org/) 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.\n\nI have already published the following posts.\n\n- [Exporting Specific Pages From a PDF as a New PDF Using Google Apps Script](https://medium.com/google-cloud/exporting-specific-pages-from-a-pdf-as-a-new-pdf-using-google-apps-script-2f22d07b4618)\n- [Management of PDF Metadata using Google Apps Script](https://medium.com/google-cloud/management-of-pdf-metadata-using-google-apps-script-60fd41f4fc16)\n- [Changing Order of Pages in PDF file using Google Apps Script](https://medium.com/google-cloud/changing-order-of-pages-in-pdf-file-using-google-apps-script-f6b3de05d7df)\n- [Merging Multiple PDF Files as a Single PDF File using Google Apps Script](https://tanaikech.github.io/2023/01/10/merging-multiple-pdf-files-as-a-single-pdf-file-using-google-apps-script/)\n- [Converting All Pages in PDF File to PNG Images using Google Apps Script](https://tanaikech.github.io/2023/01/11/converting-all-pages-in-pdf-file-to-png-images-using-google-apps-script/)\n- [Retrieving and Putting Values for PDF Forms using Google Apps Script](https://medium.com/google-cloud/retrieving-and-putting-values-for-pdf-forms-using-google-apps-script-92412a7cf0af)\n- [Creating PDF Forms from Google Slide Template using Google Apps Script](https://medium.com/google-cloud/creating-pdf-forms-from-google-slide-template-using-google-apps-script-cef35e7d9822)\n- [Embedding Objects in PDF using Google Apps Script](https://medium.com/google-cloud/embedding-objects-in-pdf-using-google-apps-script-ddbee857c642)\n- [Add Header and Footer to Exported PDF from Google Spreadsheet using Google Apps Script](https://medium.com/google-cloud/add-header-and-footer-to-exported-pdf-from-google-spreadsheet-using-google-apps-script-664fe5b190be)\n- [Adding Page Numbers to PDF using Google Apps Script](https://medium.com/google-cloud/adding-page-numbers-to-pdf-using-google-apps-script-ae964fb07655)\n\nI created this library to more efficiently manage PDFs with a simple script by summarising the scripts of these posts.\n\n# Library's project key\n\n```\n1Xmtr5XXEakVql7N6FqwdCNdpdijsJOxgqH173JSB0UOwdb0GJYJbnJLk\n```\n\n\u003ca name=\"usage\"\u003e\u003c/a\u003e\n\n# Usage\n\n## 1. Install library\n\nIn order to use this library, please install the library as follows.\n\n1. Create a GAS project.\n\n   - You can use this library for the GAS project of both the standalone and container-bound script types.\n\n1. [Install this library](https://developers.google.com/apps-script/guides/libraries).\n\n   - Library's project key is **`1Xmtr5XXEakVql7N6FqwdCNdpdijsJOxgqH173JSB0UOwdb0GJYJbnJLk`**.\n\n# Scopes\n\nThis library uses the following 3 scopes.\n\n- `https://www.googleapis.com/auth/script.external_request`\n- `https://www.googleapis.com/auth/drive`\n- `https://www.googleapis.com/auth/presentations`\n\n\n# Methods\n\n| Methods                                                 | Description                                                                                                                                                                                                                                                                                                           |\n| :-------- | :------------------ |\n| [setPDFBlob](#setpdfblob) | Give the source PDF blob. This method is used with other methods. |\n| [useStandardFont](#usestandardfont) | When you want to use the standard font, please use this method. This method is used with other methods. |\n| [useCustomFont](#usecustomfont) | When you want to use the custom font, please use this method. This method is used with other methods. |\n|||\n| [exportPages](#exportpages) | Export specific pages from a PDF blob. |\n| [getMetadata](#getmetadata) | Get PDF metadata from a PDF blob. |\n| [udpateMetadata](#udpatemetadata) | Update PDF metadata of a PDF blob. |\n| [reorderPages](#reorderpages) | Reorder pages of a PDF blob. |\n| [mergePDFs](#mergepdfs) | Merge multiple PDF files in a single PDF. |\n| [convertPDFToPng](#convertpdftopng) | Convert PDF pages to PNG images. |\n| [getValuesFromPDFForm](#getvaluesfrompdfform) | Get values from PDF Form. |\n| [setValuesToPDFForm](#setvaluestopdfform) | Set values to PDF Form. |\n| [createPDFFormBySlideTemplate](#createpdfformbyslidetemplate) | Create PDF Form By Google Slide template. |\n| [embedObjects](#embedobjects) | Embed objects into PDF blob. |\n| [insertHeaderFooter](#insertheaderfooter) | Add custom header and footer to PDF blob. |\n| [splitPDF](#splitpdf) | Split each page of a PDF to an individual PDF file. |\n| [addPageNumbers](#addpagenumbers) | Add page numbers to PDF. |\n\n\u003ca name=\"setpdfblob\"\u003e\u003c/a\u003e\n\n## setPDFBlob\n\nGive the source PDF blob. This method is used with other methods.\n\nIn this sample script, the PDF metadata is retrieved.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\n\nPDFApp.setPDFBlob(blob).getMetadata()\n  .then(res =\u003e console.log(res))\n  .catch(err =\u003e console.log(err));\n```\n\n\u003ca name=\"usestandardfont\"\u003e\u003c/a\u003e\n\n## useStandardFont\n\nWhen you want to use the standard font, please use this method. This method is used with other methods.\n\nIn this sample script, a value is put into a field of PDF Form with \"TimesRoman\".\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\nconst object = {\n  values: [\n    { \"name\": \"textbox.sample1.sample1.page1\", \"value\": \"sample update text\" }\n  ],\n};\n\nPDFApp\n.setPDFBlob(blob)\n.useStandardFont(\"TimesRoman\")\n.setValuesToPDFForm(object)\n  .then(newBlob =\u003e DriveApp.createFile(newBlob))\n  .catch(err =\u003e console.log(err));\n```\n\n\u003ca name=\"usecustomfont\"\u003e\u003c/a\u003e\n\n## useCustomFont\n\nWhen you want to use the custom font, please use this method. This method is used with other methods.\n\nIn this sample script, a value is put into a field of PDF Form with a custom font.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\nconst object = {\n  values: [\n    { \"name\": \"textbox.sample1.sample1.page1\", \"value\": \"sample update text\" }\n  ],\n};\n\nPDFApp\n.setPDFBlob(blob)\n.useCustomFont(DriveApp.getFileById(\"###fileId of font file###).getBlob())\n.setValuesToPDFForm(object)\n  .then(newBlob =\u003e DriveApp.createFile(newBlob))\n  .catch(err =\u003e console.log(err));\n```\n\n\u003ca name=\"exportpages\"\u003e\u003c/a\u003e\n\n## exportPages\n\n![](images/fig2.png)\n\nExport specific pages from a PDF blob.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\nconst pageNumbers = [2, 4, 6, 8];\n\nPDFApp.setPDFBlob(blob).exportPages(pageNumbers)\n  .then(blob =\u003e DriveApp.createFile(blob))\n  .catch(err =\u003e console.log(err));\n```\n\n- In this sample, 2, 4, 6, 8, pages are exported. And, a new PDF file is created to the root folder.\n- This is from my post \"[Exporting Specific Pages From a PDF as a New PDF Using Google Apps Script](https://medium.com/google-cloud/exporting-specific-pages-from-a-pdf-as-a-new-pdf-using-google-apps-script-2f22d07b4618)\".\n\n\u003ca name=\"getmetadata\"\u003e\u003c/a\u003e\n\n## getMetadata\n\n![](images/fig3.png)\n\nGet PDF metadata from a PDF blob.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\n\nPDFApp.setPDFBlob(blob).getMetadata()\n  .then(res =\u003e console.log(res))\n  .catch(err =\u003e console.log(err));\n```\n\n- When this script is run, the metadata is retrieved from the inputted PDF blob.\n\n- When I tested this script, I noticed that the values of `modificationDate` and `producer` might be a bug in pdf-lib. `modificationDate` returns the execution time. `producer` always 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.\n\n- This is from my post \"[Management of PDF Metadata using Google Apps Script](https://medium.com/google-cloud/management-of-pdf-metadata-using-google-apps-script-60fd41f4fc16)\".\n\n\u003ca name=\"udpatemetadata\"\u003e\u003c/a\u003e\n\n## udpateMetadata\n\n![](images/fig3.png)\n\nUpdate PDF metadata of a PDF blob.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\n\nconst object = {\n  title: [\"sample title\", { showInWindowTitleBar: true }], // This property is an array.\n  subject: \"sample subject\",\n  author: \"sample author\",\n  creator: \"sample creator\",\n  creationDate: new Date(\"2023-08-01T00:00:00\"), // This value is date object.\n  modificationDate: new Date(\"2023-08-01T10:00:00\"), // This value is date object.\n  keywords: [\"sample keyword 1\", \"sample keyword 2\", \"sample keyword 3\"], // This property is an array.\n  producer: \"sample producer\",\n};\n\nPDFApp.setPDFBlob(blob).udpateMetadata(object)\n  .then(newBlob =\u003e DriveApp.createFile(newBlob))\n  .catch(err =\u003e console.log(err));\n```\n\n- 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.\n\n- This is from my post \"[Management of PDF Metadata using Google Apps Script](https://medium.com/google-cloud/management-of-pdf-metadata-using-google-apps-script-60fd41f4fc16)\".\n\n- The detailed information of each property in the object can be seen at [https://pdf-lib.js.org/docs/api/classes/pdfdocument](https://pdf-lib.js.org/docs/api/classes/pdfdocument).\n\n\u003ca name=\"reorderpages\"\u003e\u003c/a\u003e\n\n## reorderPages\n\n![](images/fig4.png)\n\nReorder pages of a PDF blob.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\n\nconst 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.\n\nconst ignoreSkippedPages = true; // 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.\n\nPDFApp.setPDFBlob(blob).reorderPages({ newOrderOfpages, ignoreSkippedPages })\n  .then(newBlob =\u003e DriveApp.createFile(newBlob))\n  .catch(err =\u003e console.log(err));\n```\n\n- When this script is run, a new PDF file is created with the new order of pages.\n\n- When the order of pages is changed, I thought that for example, when a PDF file has 5 pages and you want to replace only the 1st page and the 2nd page, the actual exported pages are 2, 1, 3, 4, 5. But, in this script, when `ignoreSkippedPages` is used as false, this can be achieved by `newOrderOfpages` of `[2, 1]`. On the other hand, when `ignoreSkippedPages` and `newOrderOfpages` are `true` and `[2, 1]`, respectively, a new PDF file with only 2 pages of the 2nd page and the 1st page is created.\n\n- This is from my post \"[Changing Order of Pages in PDF file using Google Apps Script](https://medium.com/google-cloud/changing-order-of-pages-in-pdf-file-using-google-apps-script-f6b3de05d7df)\".\n\n\u003ca name=\"mergepdfs\"\u003e\u003c/a\u003e\n\n## mergePDFs\n\n![](images/fig5.png)\n\nMerge multiple PDF files in a single PDF.\n\n```javascript\nconst blob1 = DriveApp.getFileById(\"###fileId of PDF file 1###\").getBlob();\nconst blob2 = DriveApp.getFileById(\"###fileId of PDF file 2###\").getBlob();\nconst pdfBlobs = [blob1, blob2];\n\nPDFApp.mergePDFs(pdfBlobs)\n  .then(newBlob =\u003e DriveApp.createFile(newBlob))\n  .catch(err =\u003e console.log(err));\n```\n\n- When this script is run, the PDF of `blob1` and `blob2` are merged in order.\n\n- For example, if you want to merge 5 PDF files, please use `const pdfBlobs = [blob1, blob2, blob3, blob4, blob5]`.\n\n- This is from my post \"[Merging Multiple PDF Files as a Single PDF File using Google Apps Script](https://tanaikech.github.io/2023/01/10/merging-multiple-pdf-files-as-a-single-pdf-file-using-google-apps-script/)\".\n\n\u003ca name=\"convertpdftopng\"\u003e\u003c/a\u003e\n\n## convertPDFToPng\n\n![](images/fig6.png)\n\nConvert PDF pages to PNG images.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\n\nPDFApp.setPDFBlob(blob).convertPDFToPng()\n  .then(imageBlobs =\u003e imageBlobs.forEach(b =\u003e DriveApp.createFile(b)))\n  .catch(err =\u003e console.log(err));\n```\n\n- When this script is run, all pages of the PDF of `blob` are converted to PNG images, and those images are saved as the image files in the root folder.\n\n- This is from my post \"[Converting All Pages in PDF File to PNG Images using Google Apps Script](https://tanaikech.github.io/2023/01/11/converting-all-pages-in-pdf-file-to-png-images-using-google-apps-script/)\".\n\n- When the number of pages is large, it might be better when the PDF is split by \"exportPages\" method.\n\n\u003ca name=\"getvaluesfrompdfform\"\u003e\u003c/a\u003e\n\n## getValuesFromPDFForm\n\n![](images/fig7.png)\n\nGet values from PDF Form.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\n\nPDFApp.setPDFBlob(blob).getValuesFromPDFForm()\n  .then(res =\u003e console.log(res))\n  .catch(err =\u003e console.log(err));\n```\n\n- When this script is run, the values are retrieved from all fields of PDF form in the inputted PDF blob.\n\n- This is from my post \"[Retrieving and Putting Values for PDF Forms using Google Apps Script](https://medium.com/google-cloud/retrieving-and-putting-values-for-pdf-forms-using-google-apps-script-92412a7cf0af)\".\n\n### Limitations\n\nIn the current stage, the fields of the textbox, the checkbox, the dropdown list, and the radio button of the PDF Form can be used.\n\n\u003ca name=\"setvaluestopdfform\"\u003e\u003c/a\u003e\n\n## setValuesToPDFForm\n\n![](images/fig7.png)\n\nSet values to PDF Form.\n\n### Limitations\n\nIn the current stage, the fields of the textbox, the checkbox, the dropdown list, and the radio button of the PDF Form can be used.\n\n### Sample 1\n\nIn this sample, the default font is used.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\n\nconst object = {\n  values: [\n    { \"name\": \"textbox.sample1.sample1.page1\", \"value\": \"sample update text\" },\n    { \"name\": \"dropdownlist.sample2.sample1.page1\", \"value\": \"sample option5\" },\n    { \"name\": \"checkbox.sample3.checkbox1.page1\", \"value\": true },\n    { \"name\": \"checkbox.sample3.checkbox2.page1\", \"value\": false },\n    { \"name\": \"checkbox.sample3.checkbox3.page1\", \"value\": true },\n    { \"name\": \"radiobutton.sample4.page1\", \"value\": \"radiobutton.sample4.radiobutton2.page1\" }\n  ],\n};\n\nconst PDFA = PDFApp.setPDFBlob(blob);\nPDFA.setValuesToPDFForm(object)\n  .then(newBlob =\u003e DriveApp.createFile(newBlob))\n  .catch(err =\u003e console.log(err));\n```\n\n- When this script is run, the values of `object` are put into each field of PDF form and a new PDF blob is returned.\n\n- About the names of each field of PDF form, they can be retrieved by \"getValuesFromPDFForm\" method.\n\n- This is from my post \"[Retrieving and Putting Values for PDF Forms using Google Apps Script](https://medium.com/google-cloud/retrieving-and-putting-values-for-pdf-forms-using-google-apps-script-92412a7cf0af)\".\n\n- The detailed information about the format of `name` and each properties can be seen in [this post](https://medium.com/google-cloud/retrieving-and-putting-values-for-pdf-forms-using-google-apps-script-92412a7cf0af).\n\n### Sample 2\n\nIn this sample, the standard font is used.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\n\nconst object = {\n  values: [\n    { \"name\": \"textbox.sample1.sample1.page1\", \"value\": \"sample update text\" },\n    { \"name\": \"dropdownlist.sample2.sample1.page1\", \"value\": \"sample option5\" },\n    { \"name\": \"checkbox.sample3.checkbox1.page1\", \"value\": true },\n    { \"name\": \"checkbox.sample3.checkbox2.page1\", \"value\": false },\n    { \"name\": \"checkbox.sample3.checkbox3.page1\", \"value\": true },\n    { \"name\": \"radiobutton.sample4.page1\", \"value\": \"radiobutton.sample4.radiobutton2.page1\" }\n  ],\n};\n\nconst PDFA = PDFApp.setPDFBlob(blob).useStandardFont(\"TimesRoman\");\nPDFA.setValuesToPDFForm(object)\n  .then(newBlob =\u003e DriveApp.createFile(newBlob))\n  .catch(err =\u003e console.log(err));\n```\n\n- When this script is run, the values of `object` are put into each field of PDF form and a new PDF blob is returned. At that time, \"TimesRoman\" is used from the standard font.\n\n- The font names of the standard font can be obtained from [https://pdf-lib.js.org/docs/api/enums/standardfonts](https://pdf-lib.js.org/docs/api/enums/standardfonts).\n\n- The detailed information about the format of `name` and each properties can be seen in [this post](https://medium.com/google-cloud/retrieving-and-putting-values-for-pdf-forms-using-google-apps-script-92412a7cf0af).\n\n### Sample 3\n\nIn this sample, the custom font is used.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\n\nconst object = {\n  values: [\n    { \"name\": \"textbox.sample1.sample1.page1\", \"value\": \"サンプルテキスト1\" },\n    { \"name\": \"dropdownlist.sample2.sample1.page1\", \"value\": \"sample option5\" },\n    { \"name\": \"checkbox.sample3.checkbox1.page1\", \"value\": true },\n    { \"name\": \"checkbox.sample3.checkbox2.page1\", \"value\": false },\n    { \"name\": \"checkbox.sample3.checkbox3.page1\", \"value\": true },\n    { \"name\": \"radiobutton.sample4.page1\", \"value\": \"radiobutton.sample4.radiobutton2.page1\" }\n  ],\n};\n\nconst PDFA = PDFApp.setPDFBlob(blob).useCustomFont(DriveApp.getFileById(\"###fileId of font file###\").getBlob());\nPDFA.setValuesToPDFForm(object)\n  .then(newBlob =\u003e DriveApp.createFile(newBlob))\n  .catch(err =\u003e console.log(err));\n```\n\n- When this script is run, the values of `object` are put into each field of PDF form and a new PDF blob is returned. At that time, the custom font is used. For example, when you want to put Japanese language, the custom font is required to be used.\n\n- About the custom font, TTF and OTF files can be used.\n\n- The detailed information about the format of `name` and each properties can be seen in [this post](https://medium.com/google-cloud/retrieving-and-putting-values-for-pdf-forms-using-google-apps-script-92412a7cf0af).\n\n\u003ca name=\"createpdfformbyslidetemplate\"\u003e\u003c/a\u003e\n\n## createPDFFormBySlideTemplate\n\n![](images/fig8.png)\n\nCreate PDF Form By Google Slide template.\n\nAbout `methods` property in the object, the method name can be confirmed at the official document. [Ref](https://pdf-lib.js.org/docs/api/)\n\n- Textbox: [https://pdf-lib.js.org/docs/api/classes/pdftextfield](https://pdf-lib.js.org/docs/api/classes/pdftextfield)\n- Checkbox: [https://pdf-lib.js.org/docs/api/classes/pdfcheckbox](https://pdf-lib.js.org/docs/api/classes/pdfcheckbox)\n- Dropdown list: [https://pdf-lib.js.org/docs/api/classes/pdfdropdown](https://pdf-lib.js.org/docs/api/classes/pdfdropdown)\n- Radio button: [https://pdf-lib.js.org/docs/api/classes/pdfradiogroup](https://pdf-lib.js.org/docs/api/classes/pdfradiogroup)\n\nFor example, when you want to create a textbox, when `{ shapeTitle: \"textbox.sample1.sample1\", methods: [{ method: \"setText\", value: \"sample text1\" }]}` is used, a textbox including `sample text1` is created to the shape with the shape title of `textbox.sample1.sample1`.\n\n### Limitations\n\nIn the current stage, the fields of the textbox, the checkbox, the dropdown list, and the radio button of the PDF Form can be created.\n\n### Preparation\n\nIn this case, first, please create a Google Slide as a template as follows.\n\n![](images/fig8b.png)\n\nIn the template slide, please set shapes and please set the shape titles. The shape title is required to be the unique value in the slide. Please be careful about this. The following script converts the template shapes to the fields of the PDF form using the shape titles. The flow of this is as follows.\n\n1. Create a new Google Slide.\n\n2. Put texts and shapes on the slide.\n\n3. Texts are used as the text in PDF.\n  - Shapes are converted to the fields in PDF form.\n  - Set the ID to the shape title (Alt Text).\n\n4. There is a rule regarding the format of ID. Please check the section “Rule of shape title (Alt Text)”.\n\n### Rule of shape title (Alt Text)\n\nThe format of ID (shape title (Alt Text)) is as follows.\n\n```\n{field type}.{group name}.{field name}\n```\n\nWhen the above sample Google Slide template is used, the IDs of fields of PDF form are as follows.\n\n- Textbox\n  - `textbox.sample1.sample1`\n  - `textbox.sample1.sample2`\n- Checkbox\n  - `checkbox.sample2.checkbox1`\n  - `checkbox.sample2.checkbox2`\n  - `checkbox.sample2.checkbox3`\n- Dropdown\n  - `dropdownlist.sample4.sample1`\n- Radiobutton\n  - `radiobutton.sample5.radiobutton1`\n  - `radiobutton.sample5.radiobutton2`\n  - `radiobutton.sample5.radiobutton3`\n\nIn the case of `radiobutton.sample5.radiobutton1`, `radiobutton` is a type of field. `sample5` is a group of fields. `radiobutton1` is a unique name of the group. `radiobutton.sample5` has 3 fields of `radiobutton.sample5.radiobutton1`, `radiobutton.sample5.radiobutton2`, and `radiobutton.sample5.radiobutton3`.\n\n### Sample 1\n\nIn this sample, the default font is used.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\nconst templateId = \"###\"; // Please set the file ID of your Google Slide template.\n\nconst object = {\n  values: [\n    {\n      shapeTitle: \"textbox.sample1.sample1\",\n      methods: [{ method: \"setText\", value: \"sample text1\" }],\n    },\n    {\n      shapeTitle: \"checkbox.sample2.checkbox1\",\n      methods: [{ method: \"enableRequired\" }],\n    },\n    {\n      shapeTitle: \"checkbox.sample2.checkbox2\",\n      methods: [{ method: \"enableRequired\" }, { method: \"check\" }],\n    },\n    {\n      shapeTitle: \"checkbox.sample2.checkbox3\",\n      methods: [{ method: \"enableRequired\" }, { method: \"check\" }],\n    },\n    {\n      shapeTitle: \"textbox.sample1.sample2\",\n      methods: [\n        { method: \"setText\", value: \"sample text2\" },\n        { method: \"enableMultiline\" },\n        { method: \"setFontSize\", value: \"12\" },\n      ],\n    },\n    {\n      shapeTitle: \"dropdownlist.sample4.sample1\",\n      methods: [\n        {\n          method: \"setOptions\",\n          value: [\n            \"sample option1\",\n            \"sample option2\",\n            \"sample option3\",\n            \"sample option4\",\n            \"sample option5\",\n          ],\n        },\n        { method: \"enableEditing\" },\n        { method: \"enableMultiselect\" },\n        { method: \"select\", value: \"sample option3\" },\n      ],\n    },\n    {\n      shapeTitle: \"radiobutton.sample5.radiobutton1\",\n      methods: [{ method: \"enableRequired\" }],\n    },\n    {\n      shapeTitle: \"radiobutton.sample5.radiobutton2\",\n      methods: [\n        { method: \"enableRequired\" },\n        { method: \"select\", value: \"radiobutton.sample5.radiobutton2\" },\n      ],\n    },\n    {\n      shapeTitle: \"radiobutton.sample5.radiobutton3\",\n      methods: [{ method: \"enableRequired\" }],\n    },\n  ],\n};\n\nconst templateSlide = DriveApp.getFileById(templateId);\nconst folder = templateSlide.getParents().next();\nconst temp = templateSlide.makeCopy(\"temp\", folder);\nconst tempId = temp.getId();\nPDFApp.createPDFFormBySlideTemplate(tempId, object)\n  .then(newBlob =\u003e {\n    folder.createFile(newBlob);\n    temp.setTrashed(true);\n  })\n  .catch(err =\u003e console.log(err));\n```\n\n- When this script is run, a PDF form is created from Google Slide template.\n\n  ![](images/fig8c.png)\n\n- `shapeTitle`: Shape title (Alt Text).\n\n- `method` in `methods`: Method names of Class PDFCheckBox, PDFDropdown, PDFRadioGroup, and PDFTextField.\n\n- `value` in `methods`: Arguments of the methods of Class PDFCheckBox, PDFDropdown, PDFRadioGroup, and PDFTextField.\n\n- This is from my post \"[Creating PDF Forms from Google Slide Template using Google Apps Script](https://medium.com/google-cloud/creating-pdf-forms-from-google-slide-template-using-google-apps-script-cef35e7d9822)\".\n\n- The detailed information about the format of `name` and each properties can be seen in [this post](https://medium.com/google-cloud/creating-pdf-forms-from-google-slide-template-using-google-apps-script-cef35e7d9822).\n\n### Sample 2\n\nIn this sample, the standard font is used.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\nconst templateId = \"###\"; // Please set the file ID of your Google Slide template.\n\nconst object = {\n  values: [\n    {\n      shapeTitle: \"textbox.sample1.sample1\",\n      methods: [{ method: \"setText\", value: \"sample text1\" }],\n    },\n    {\n      shapeTitle: \"checkbox.sample2.checkbox1\",\n      methods: [{ method: \"enableRequired\" }],\n    },\n    {\n      shapeTitle: \"checkbox.sample2.checkbox2\",\n      methods: [{ method: \"enableRequired\" }, { method: \"check\" }],\n    },\n    {\n      shapeTitle: \"checkbox.sample2.checkbox3\",\n      methods: [{ method: \"enableRequired\" }, { method: \"check\" }],\n    },\n    {\n      shapeTitle: \"textbox.sample1.sample2\",\n      methods: [\n        { method: \"setText\", value: \"sample text2\" },\n        { method: \"enableMultiline\" },\n        { method: \"setFontSize\", value: \"12\" },\n      ],\n    },\n    {\n      shapeTitle: \"dropdownlist.sample4.sample1\",\n      methods: [\n        {\n          method: \"setOptions\",\n          value: [\n            \"sample option1\",\n            \"sample option2\",\n            \"sample option3\",\n            \"sample option4\",\n            \"sample option5\",\n          ],\n        },\n        { method: \"enableEditing\" },\n        { method: \"enableMultiselect\" },\n        { method: \"select\", value: \"sample option3\" },\n      ],\n    },\n    {\n      shapeTitle: \"radiobutton.sample5.radiobutton1\",\n      methods: [{ method: \"enableRequired\" }],\n    },\n    {\n      shapeTitle: \"radiobutton.sample5.radiobutton2\",\n      methods: [\n        { method: \"enableRequired\" },\n        { method: \"select\", value: \"radiobutton.sample5.radiobutton2\" },\n      ],\n    },\n    {\n      shapeTitle: \"radiobutton.sample5.radiobutton3\",\n      methods: [{ method: \"enableRequired\" }],\n    },\n  ],\n};\n\nconst templateSlide = DriveApp.getFileById(templateId);\nconst folder = templateSlide.getParents().next();\nconst temp = templateSlide.makeCopy(\"temp\", folder);\nconst tempId = temp.getId();\nconst PDFA = PDFApp.useStandardFont(\"TimesRoman\"); // https://pdf-lib.js.org/docs/api/enums/standardfonts\nPDFA.createPDFFormBySlideTemplate(tempId, object)\n  .then(newBlob =\u003e {\n    folder.createFile(newBlob);\n    temp.setTrashed(true);\n  })\n  .catch(err =\u003e console.log(err));\n```\n\n- `shapeTitle`: Shape title (Alt Text).\n\n- `method` in `methods`: Method names of Class PDFCheckBox, PDFDropdown, PDFRadioGroup, and PDFTextField.\n\n- `value` in `methods`: Arguments of the methods of Class PDFCheckBox, PDFDropdown, PDFRadioGroup, and PDFTextField.\n\n- When the standard font of pdf-lib, please modify the above script as follows. The value can be known at [here](https://pdf-lib.js.org/docs/api/enums/standardfonts). For example, when you want to use \"TimesRoman\", please set `{ standardFont: \"TimesRoman\" }`.\n\n- This is from my post \"[Creating PDF Forms from Google Slide Template using Google Apps Script](https://medium.com/google-cloud/creating-pdf-forms-from-google-slide-template-using-google-apps-script-cef35e7d9822)\".\n\n- The detailed information about the format of `name` and each properties can be seen in [this post](https://medium.com/google-cloud/creating-pdf-forms-from-google-slide-template-using-google-apps-script-cef35e7d9822).\n\n### Sample 3\n\nIn this sample, the custom font is used.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\nconst templateId = \"###\"; // Please set the file ID of your Google Slide template.\nconst fileIdOfFontFile = \"###\"; // Please set the file ID of the custom font. TTF and OTF.\n\nconst object = {\n  values: [\n    {\n      shapeTitle: \"textbox.sample1.sample1\",\n      methods: [{ method: \"setText\", value: \"sample text1\" }],\n    },\n    {\n      shapeTitle: \"checkbox.sample2.checkbox1\",\n      methods: [{ method: \"enableRequired\" }],\n    },\n    {\n      shapeTitle: \"checkbox.sample2.checkbox2\",\n      methods: [{ method: \"enableRequired\" }, { method: \"check\" }],\n    },\n    {\n      shapeTitle: \"checkbox.sample2.checkbox3\",\n      methods: [{ method: \"enableRequired\" }, { method: \"check\" }],\n    },\n    {\n      shapeTitle: \"textbox.sample1.sample2\",\n      methods: [\n        { method: \"setText\", value: \"sample text2\" },\n        { method: \"enableMultiline\" },\n        { method: \"setFontSize\", value: \"12\" },\n      ],\n    },\n    {\n      shapeTitle: \"dropdownlist.sample4.sample1\",\n      methods: [\n        {\n          method: \"setOptions\",\n          value: [\n            \"sample option1\",\n            \"sample option2\",\n            \"sample option3\",\n            \"sample option4\",\n            \"sample option5\",\n          ],\n        },\n        { method: \"enableEditing\" },\n        { method: \"enableMultiselect\" },\n        { method: \"select\", value: \"sample option3\" },\n      ],\n    },\n    {\n      shapeTitle: \"radiobutton.sample5.radiobutton1\",\n      methods: [{ method: \"enableRequired\" }],\n    },\n    {\n      shapeTitle: \"radiobutton.sample5.radiobutton2\",\n      methods: [\n        { method: \"enableRequired\" },\n        { method: \"select\", value: \"radiobutton.sample5.radiobutton2\" },\n      ],\n    },\n    {\n      shapeTitle: \"radiobutton.sample5.radiobutton3\",\n      methods: [{ method: \"enableRequired\" }],\n    },\n  ],\n};\n\nconst templateSlide = DriveApp.getFileById(templateId);\nconst folder = templateSlide.getParents().next();\nconst temp = templateSlide.makeCopy(\"temp\", folder);\nconst tempId = temp.getId();\nconst PDFA = PDFApp.useCustomFont(DriveApp.getFileById(fileIdOfFontFile).getBlob());\nPDFA.createPDFFormBySlideTemplate(tempId, object)\n  .then(newBlob =\u003e {\n    folder.createFile(newBlob);\n    temp.setTrashed(true);\n  })\n  .catch(err =\u003e console.log(err));\n```\n\n- When this script is run, a PDF form is created from Google Slide template.\n\n  ![](images/fig8d.png)\n\n- `shapeTitle`: Shape title (Alt Text).\n\n- `method` in `methods`: Method names of Class PDFCheckBox, PDFDropdown, PDFRadioGroup, and PDFTextField.\n\n- `value` in `methods`: Arguments of the methods of Class PDFCheckBox, PDFDropdown, PDFRadioGroup, and PDFTextField.\n\n- In order to use the custom font, please prepare the font you want to use. `TTF` and `OTF` files can be used.\n\n- This is from my post \"[Creating PDF Forms from Google Slide Template using Google Apps Script](https://medium.com/google-cloud/creating-pdf-forms-from-google-slide-template-using-google-apps-script-cef35e7d9822)\".\n\n- The detailed information about the format of `name` and each properties can be seen in [this post](https://medium.com/google-cloud/creating-pdf-forms-from-google-slide-template-using-google-apps-script-cef35e7d9822).\n\n\u003ca name=\"embedobjects\"\u003e\u003c/a\u003e\n\n## embedObjects\n\n![](images/fig9.png)\n\nEmbed objects into PDF blob.\n\n### Limitations\n\nIn the current stage, the objects of texts and images can be embedded in a PDF.\n\n### Sample 1\n\nIn this sample, the default font is used.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\nconst object = {\n  page1: [\n    { text: \"sample text1\", x: 150, y: 635, size: 30 },\n    { text: \"sample text2\", x: 390, y: 602, size: 16 },\n    { imageFileId: \"### file ID of image file ###\", x: 175, y: 340, scale: 0.35 },\n  ],\n};\nPDFApp.setPDFBlob(blob).embedObjects(object)\n  .then(newBlob =\u003e DriveApp.createFile(newBlob))\n  .catch(err =\u003e console.log(err));\n```\n\n- When this script is run, 2 texts and 1 image are embedded to the 1st page of the PDF file with the default font.\n\n  - From\n\n      ![](images/fig9b.png)\n\n  - To\n\n      ![](images/fig9c.png)\n\n- In this case, `object` is constructed as follows. By this, you can set the objects for each page.\n\n```javascript\nconst object = {\n  page1: [\n    { text: \"sample text1\", x: 150, y: 635, size: 30 },\n    { text: \"sample text2\", x: 390, y: 602, size: 16 },\n    { imageFileId: \"### file ID of image file ###\", x: 175, y: 340, scale: 0.35 },\n  ],\n  page2: [,,,],\n  page3: [,,,],\n  ,\n  ,\n  ,\n};\n```\n\n- This is from my post \"[Embedding Objects in PDF using Google Apps Script](https://medium.com/google-cloud/embedding-objects-in-pdf-using-google-apps-script-ddbee857c642)\".\n\n- The detailed information about the format of `name` and each properties can be seen in [this post](https://medium.com/google-cloud/embedding-objects-in-pdf-using-google-apps-script-ddbee857c642).\n\n### Sample 2\n\nIn this sample, the standard font is used.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\nconst object = {\n  page1: [\n    { text: \"sample text1\", x: 150, y: 635, standardFont: \"Helvetica\", size: 30 },\n    { text: \"sample text2\", x: 390, y: 602, standardFont: \"TimesRoman\", size: 16 },\n    { imageFileId: \"### file ID of image file ###\", x: 175, y: 340, scale: 0.35 },\n  ],\n};\nPDFApp.setPDFBlob(blob).embedObjects(object)\n  .then(newBlob =\u003e DriveApp.createFile(newBlob))\n  .catch(err =\u003e console.log(err));\n```\n\n- When this script is run, 2 texts and 1 image are embedded to the 1st page of the PDF file with the standard font.\n\n- This is from my post \"[Embedding Objects in PDF using Google Apps Script](https://medium.com/google-cloud/embedding-objects-in-pdf-using-google-apps-script-ddbee857c642)\".\n\n- The detailed information about the format of `name` and each properties can be seen in [this post](https://medium.com/google-cloud/embedding-objects-in-pdf-using-google-apps-script-ddbee857c642).\n\n### Sample 3\n\nIn this sample, the custom font is used.\n\n```javascript\nconst blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\nconst object = {\n  page1: [\n    { text: \"sample text1\", x: 150, y: 635, customFont: DriveApp.getFileById(\"### file ID of custom font file ###\").getBlob(), size: 30 },\n    { text: \"sample text2\", x: 390, y: 602, standardFont: \"TimesRoman\", size: 16 },\n    { imageFileId: \"### file ID of image file ###\", x: 175, y: 340, scale: 0.35 },\n  ],\n};\nPDFApp.setPDFBlob(blob).embedObjects(object)\n  .then(newBlob =\u003e DriveApp.createFile(newBlob))\n  .catch(err =\u003e console.log(err));\n```\n\n- When this script is run, 2 texts and 1 image are embedded to the 1st page of the PDF file with the custom font. For example, when you want to use the Japanese language, it is required to use the custom font.\n\n- This is from my post \"[Embedding Objects in PDF using Google Apps Script](https://medium.com/google-cloud/embedding-objects-in-pdf-using-google-apps-script-ddbee857c642)\".\n\n- The detailed information about the format of `name` and each properties can be seen in [this post](https://medium.com/google-cloud/embedding-objects-in-pdf-using-google-apps-script-ddbee857c642).\n\n\u003ca name=\"insertheaderfooter\"\u003e\u003c/a\u003e\n\n## insertHeaderFooter\n\n![](images/fig10.png)\n\nAdd custom header and footer to PDF blob.\n\nWhen this method is used, the result showin in my blog can be obtained. [Ref](https://medium.com/google-cloud/add-header-and-footer-to-exported-pdf-from-google-spreadsheet-using-google-apps-script-664fe5b190be)\n\n### Sample script 1\nIn this sample, the default font is used.\n\n```javascript\nfunction sample() {\n  const object = {\n    header: {\n      left: { height: 30, alignment: \"Center\", text: \"sample text h1\" },\n      center: { height: 30, alignment: \"Center\", text: \"sample text h2\" },\n      right: { height: 30, alignment: \"Center\", text: \"sample text h3\" },\n    },\n    footer: {\n      left: { height: 30, alignment: \"Center\", text: \"sample text f1\" },\n      center: { height: 30, alignment: \"Center\", text: \"sample text f2\" },\n      right: { height: 30, alignment: \"Center\", text: \"sample text f3\" },\n    },\n  }\n\n  const blob = SpreadsheetApp.getActiveSpreadsheet().getBlob()\n  const PDFA = PDFApp.setPDFBlob(blob)\n  PDFA.insertHeaderFooter(object)\n    .then(blob =\u003e DriveApp.createFile(blob))\n    .catch(err =\u003e console.log(err));\n}\n```\n\n### Sample script 2\nIn this sample, the standard font is used.\n\n```javascript\nfunction sample() {\n  const object = {\n    header: {\n      left: { height: 30, alignment: \"Center\", text: \"sample text h1\" },\n      center: { height: 30, alignment: \"Center\", text: \"sample text h2\" },\n      right: { height: 30, alignment: \"Center\", text: \"sample text h3\" },\n    },\n    footer: {\n      left: { height: 30, alignment: \"Center\", text: \"sample text f1\" },\n      center: { height: 30, alignment: \"Center\", text: \"sample text f2\" },\n      right: { height: 30, alignment: \"Center\", text: \"sample text f3\" },\n    },\n  }\n\n  const blob = SpreadsheetApp.getActiveSpreadsheet().getBlob();\n  const PDFA = PDFApp.setPDFBlob(blob).useStandardFont(\"TimesRoman\");\n  PDFA.insertHeaderFooter(object)\n    .then(blob =\u003e DriveApp.createFile(blob))\n    .catch(err =\u003e console.log(err));\n}\n```\n\n### Sample script 3\nIn this sample, the custom font is used.\n\n```javascript\nfunction sample2() {\n  const object = {\n    header: {\n      left: { height: 30, alignment: \"Center\", text: \"sample text h1\" },\n      center: { height: 30, alignment: \"Center\", text: \"sample text h2\" },\n      right: { height: 30, alignment: \"Center\", text: \"sample text h3\" },\n    },\n    footer: {\n      left: { height: 30, alignment: \"Center\", text: \"sample text f1\" },\n      center: { height: 30, alignment: \"Center\", text: \"sample text f2\" },\n      right: { height: 30, alignment: \"Center\", text: \"sample text f3\" },\n    },\n  }\n\n  const fileIdOfFontFile = \"###\"; // File ID of font file (TTF and OTF)\n  const blob = SpreadsheetApp.getActiveSpreadsheet().getBlob();\n  const PDFA = PDFApp.setPDFBlob(blob).useCustomFont(DriveApp.getFileById(fileIdOfFontFile).getBlob());\n  PDFA.insertHeaderFooter(object)\n    .then(blob =\u003e DriveApp.createFile(blob))\n    .catch(err =\u003e console.log(err));\n}\n```\n\n\u003ca name=\"splitpdf\"\u003e\u003c/a\u003e\n\n## splitPDF\n\nSplit each page of a PDF to an individual PDF file.\n\n### Sample script\n\n```javascript\nfunction sample() {\n  const blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\n  PDFApp.setPDFBlob(blob).splitPDF()\n    .then(blobs =\u003e {\n      console.log(blobs.length);\n      blobs.forEach(blob =\u003e DriveApp.createFile(blob));\n    })\n    .catch(err =\u003e console.log(err));\n}\n```\n\n- When this script is run, each page of the source PDF file is created each PDF file.\n\n\u003ca name=\"addpagenumbers\"\u003e\u003c/a\u003e\n\n## addPageNumbers\n\nAdd page numbers to PDF.\n\n### Sample script\n\n```javascript\nfunction sample() {\n  const blob = DriveApp.getFileById(\"###fileId of PDF file###\").getBlob();\n\n  const object = { size: 10, x: \"center\", y: 10 };\n  PDFApp.setPDFBlob(blob).addPageNumbers(object)\n    .then(newBlob =\u003e DriveApp.createFile(newBlob))\n    .catch(err =\u003e console.log(err));\n}\n```\n\nThe sample demonstration script is as follows. When the following script is run, a new Google Document is created and the page numbers are added to each page of the PDF.\n\n```javascript\nfunction sample() {\n  // Create a sample Google Document.\n  const tempDoc = DocumentApp.create(\"tempDoc\");\n  const body = tempDoc.getBody();\n  for (let p = 0; p \u003c 5; p++) {\n    body.appendParagraph(`sample text ${p + 1}`).appendPageBreak();\n  }\n  tempDoc.saveAndClose();\n  const blob = tempDoc.getBlob();\n\n  const object = { size: 10, x: \"center\", y: 10 };\n  PDFApp.setPDFBlob(blob).addPageNumbers(object)\n    .then(newBlob =\u003e DriveApp.createFile(newBlob))\n    .catch(err =\u003e console.log(err));\n}\n```\n\n- When this script is run, the page numbers are put to the center of the bottom of each page.\n- You can simply customize the page numbers by modifying `const object = { size: 10, x: \"center\", y: 10 }`. The value of `x` can be selected as one of \"left\", \"center\", and \"right\".\n- In this method, a simple format like `{ size: 10, x: \"center\", y: 10 }` is used for the page numbers. Here, the page numbers are put to only \"left\", \"center\", and \"right\" of the bottom of the page. The page numbers can be customized variously. So, when you want to customize more, I would like to recommend using the script on [my blog](https://medium.com/google-cloud/adding-page-numbers-to-pdf-using-google-apps-script-ae964fb07655) by modifying.\n- When a number is used to the property `x` instead of \"left\", \"center\", and \"right\", the inputted number is directly used. For example, you can also use `const object = { size: 10, x: 10, y: 10 };` instead of `const object = { size: 10, x: \"center\", y: 10 };`.\n\n---\n\n\u003ca name=\"licence\"\u003e\u003c/a\u003e\n\n# Licence\n\n[MIT](LICENCE)\n\n\u003ca name=\"author\"\u003e\u003c/a\u003e\n\n# Author\n\n[Tanaike](https://tanaikech.github.io/about/)\n\n[Donate](https://tanaikech.github.io/donate/)\n\n\u003ca name=\"updatehistory\"\u003e\u003c/a\u003e\n\n# Update History\n\n- v1.0.0 (August 17, 2023)\n\n  1. Initial release.\n\n- v1.0.1 (August 18, 2023)\n\n  1. About the method of \"getMetadata\", `pageInfo` is added to the retrieved metadata. By this, each page size can be obtained.\n\n- v1.0.2 (August 21, 2023)\n\n  1. A new method of `insertHeaderFooter` was added. [Ref](#insertheaderfooter) When this method is used, the custom header and footer can be added when a Google Spreadsheet is exported as PDF.\n\n- v1.0.3 (November 26, 2023)\n\n  1. From [this discussion](https://github.com/Hopding/pdf-lib/issues/252), I changed the logic of the method `mergePDFs`. The method for using `mergePDFs` and the output are not changed. With this modification, the large PDF data can be merged.\n\n- v1.0.4 (February 5, 2024)\n\n  1. From [this discussion](https://github.com/Hopding/pdf-lib/issues/252), I changed the logic of `copyPages`.\n\n- v1.0.5 (February 5, 2024)\n\n  1. A new method of \"splitPDF\" was added. [Ref](#splitpdf) This method splits each page of a PDF to an individual PDF file.\n\n- v1.0.6 (May 15, 2024)\n\n  1. A new method of \"addPageNumbers\" was added. [Ref](#addpagenumbers) This method adds the page numbers to each page of the PDF.\n\n- v1.0.7 (May 15, 2024)\n\n  1. The method of \"addPageNumbers\" was updated. [Ref](#addpagenumbers) When a number is used to the property `x` instead of \"left\", \"center\", and \"right\", the inputted number is directly used.\n\n[TOP](#top)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanaikech%2FPDFApp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftanaikech%2FPDFApp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanaikech%2FPDFApp/lists"}