Link Search Menu Expand Document

Split All PDF in Google Drive Folder - GoogleAppScript

PDF Split sample in GoogleAppScript demonstrating ‘Split All PDF in Google Drive Folder’
function splitPDFDocuments() {
  // Set Google Drive Folder ID
  var googleDriveFolderId='YOUR_FOLDER_ID';
  // Set API Key
  var pdfCoAPIKey='YOUR_API_KEY';

  // Get Files from Google Drive Folder
  var files = DriveApp.getFolderById(googleDriveFolderId).getFiles()

  while (files.hasNext()) {
    var file =;
    file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);

  // Prepare Payload
  var data = {
    "async": false,
    "encrypt": false,
    "inline": true,
    "name": "result",
    "url": file.getDownloadUrl(),
    "pages": "*"

  // 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)

  var pdfCoResponse = UrlFetchApp.fetch('', options);

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

  var resultUrls = pdfCoRespJson.urls;
  // Save Split PDFs in Google Drive Folder
  for(let i=0;i<resultUrls.length;i++) {
    var splitFile = UrlFetchApp.fetch(resultUrls[i]).getBlob();

} 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 Split endpoint