Automatically Remove Specific Pages from PDFs in Google Drive Using n8n and PDF.co

Oct 16, 2025·4 Minutes Read

What You’ll Have When Done

You’ll have a fully automated n8n workflow that:

  • Watches a Google Drive folder for new PDF uploads
  • Searches for specific text in the PDF (e.g., company names, keywords)
  • Identifies the pages containing that text
  • Deletes those pages automatically using PDF.co
  • Saves the cleaned PDF into another Google Drive folder — no manual editing needed.

Prerequisites

Before you begin, make sure you have:

  • Two Google Drive folders:
    • Input Folder → where PDFs are uploaded (e.g., INPUT_FOLDER)
    • Output Folder → where processed PDFs will be saved (e.g., OUTPUT_FOLDER)
  • A running n8n instance (self-hosted or cloud)
  • A valid PDF.co API keyhttps://app.pdf.co/
  • Google Drive OAuth2 credentials set up in n8n
  • A sample PDF file you can test with.

Download Sample PDF (or use any of your own)

Quick Start Options

Option A — Import Ready-to-Use Workflow

  • Download & import the JSON provided below- JSON File
  • Connect your Google Drive and PDF.co accounts
  • Link your input & output folders
  • Test it by uploading a PDF with the target text.

Option B — Build It Step-by-Step

  • Follow the guide below to build your workflow manually.

What This Automation Does

  1. Google Drive Trigger — watches a folder for new PDFs
  2. PDF.co Search — finds target text and its page numbers
  3. Code Node — extracts those page indexes
  4. PDF.co Delete Pages — removes matched pages
  5. HTTP Request — downloads the updated PDF
  6. Google Drive Upload — saves the new version to another folder

Step-by-Step Tutorial

Step 1: Set Up Google Drive Folders

  • Create INPUT_FOLDER and OUTPUT_FOLDER in Google Drive.
  • Copy the folder IDs from their URLs.

Success looks like: Two accessible folders with their IDs ready to use in n8n.

Step 2: Google Drive Trigger

Node: Google Drive Trigger Settings:

  • Trigger On: Specific Folder
  • Folder to Watch: INPUT_FOLDER
  • Event: File Created
  • Poll Time: Every Minute

Result: The workflow starts whenever a new PDF is uploaded to the input folder.

Step 3: Search for Target Text

Node: PDF.co API – Search in PDF Settings:

  • Operation: Search in PDF
  • URL: ={{ $json.webContentLink }}
  • Search String: e.g. Atlas Office Solutions (can be dynamic too)

Result: PDF.co returns all pages containing the target string.

Sample output:

{

"body": [

{ "pageIndex": 2 },

{ "pageIndex": 5 }

]

}

Step 4: Extract Page Indexes

Node: Code (JavaScript) This node converts the list of page indexes into a clean, comma-separated string.

const items = $input.all();

const body = items[0].json.body || [];

const pageIndexes = body.map(entry => entry.pageIndex);

pageIndexes.sort((a, b) => a - b);

return [{ json: { pageIndexes: pageIndexes.join(',') } }];

Result:

{

"pageIndexes": "2,5"

}

Step 5: Delete Pages

Node: PDF.co API – Delete PDF Pages Settings:

  • URL: ={{ $('Google Drive Trigger').item.json.webContentLink }}
  • Pages: ={{ $json.pageIndexes }}

Result: PDF.co returns a URL to the updated PDF without the unwanted pages:

{

"url": "https://pdf-co-temp-files.s3.amazonaws.com/Cleaned_File.pdf",

"name": "Cleaned_MyDocument.pdf"

}

Step 6: Download File

Node: HTTP Request

Settings:

  • Method: GET
  • URL: ={{ $json.url }}

Result: n8n retrieves the binary version of the cleaned PDF.

Step 7: Upload to Google Drive

Node: Google Drive – Upload

Settings:

  • Input Data Field: data
  • File Name: Cleaned_{{ $json.name }}
  • Folder: OUTPUT_FOLDER
  • Drive: My Drive

Result: The processed PDF appears in the output folder automatically.

Step 8: Test the Automation

  • Upload a sample PDF to your INPUT folder.
  • Wait 30–60 seconds.
  • Check your OUTPUT folder — the unwanted pages are gone.

Congratulations!

You’ve built a fully automated n8n workflow that:

  • Detects new PDFs in Google Drive
  • Searches and removes pages dynamically
  • Uploads the final version to a new folder
  • Runs hands-free!

Built something amazing? Share your workflow and tag us @pdfdotco — we’d love to feature your automation!

Related Tutorials

See Related Tutorials