メインコンテンツにスキップ

PDFApp

This is a Google Apps Script library for managing PDFs.

AI Summary

PDFApp

GAS library wrapping pdf-lib for PDF management.

Target Users

Intermediate GAS developers automating PDF editing, merging, forms.

Problems Solved

GAS lacks built-in methods for direct PDF management requiring pdf-lib.

Script ID

  1. In GAS Editor: Click "Libraries +" → Paste into "Script ID" field → Click "Look up"
  2. "PDFApp" will appear in the search results
  3. Select the latest version (highest number) from "Version" dropdown
  4. Click "Add"

Tags

Main Features
1
Page Export

Exports specific pages from a PDF blob to a new PDF file.

2
PDF Merge

Merges multiple PDF blobs into a single PDF file in order.

3
Form Handling

Gets and sets values in PDF forms supporting standard/custom fonts.

Examples

Main Functions

FunctionDescription
PDFApp.setPDFBlobSets source PDF blob.
PDFApp.exportPagesExports specific pages.
PDFApp.mergePDFsMerges multiple PDFs.

Examples

Export Specific Pages
/**
 * 特定ページ抽出
 * ・PDF Blob取得: DriveApp.getFileById("###fileId of PDF file###").getBlob();
 * ・Blob設定とページ抽出: PDFApp.setPDFBlob(blob).exportPages(pageNumbers)
 * ・新PDF作成: .then(blob => DriveApp.createFile(blob))
 */
function exportSpecificPages() {
  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));
}

Merge Multiple PDFs
/**
 * 複数PDF結合
 * ・複数Blob配列: const pdfBlobs = [blob1, blob2];
 * ・結合実行: PDFApp.mergePDFs(pdfBlobs)
 * ・結果保存: .then(newBlob => DriveApp.createFile(newBlob))
 */
function mergePDFsSample() {
  const blob1 = DriveApp.getFileById("###fileId of PDF file 1###").getBlob();
  const blob2 = DriveApp.getFileById("###fileId of PDF file 2###").getBlob();
  const pdfBlobs = [blob1, blob2];

  PDFApp.mergePDFs(pdfBlobs)
    .then(newBlob => DriveApp.createFile(newBlob))
    .catch(err => console.log(err));
}

Get PDF Metadata
/**
 * PDFメタデータ取得
 * ・Blob取得: DriveApp.getFileById("###fileId of PDF file###").getBlob();
 * ・Blob設定と取得: PDFApp.setPDFBlob(blob).getMetadata()
 * ・結果出力: .then(res => console.log(res))
 */
function getMetadataSample() {
  const blob = DriveApp.getFileById("###fileId of PDF file###").getBlob();

  PDFApp.setPDFBlob(blob).getMetadata()
    .then(res => console.log(res))
    .catch(err => console.log(err));
}

Sample Code

Post a Sample

No sample codes for this library yet

Be the first to post a sample!

Post a Sample