You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Adobe Acrobat Pro JS脚本优化需求:提取2页PDF至目标文件夹

Fixing the Script to Include 2-Page PDFs in Adobe Acrobat Pro

Got it, let's tweak that script so it catches those 2-page PDFs too! The core issue here is the original logic was only targeting PDFs with more than 2 pages—we just need to adjust the condition to include exactly 2 pages as well.

Here's the Revised Script

var re = /\.pdf$/i;
var filename = this.documentFileName.replace(re, "");
// Replace this with your actual target folder path (use double backslashes for Windows)
var targetFolder = "/path/to/your/destination/folder/"; 

try {
    // Key change: Check for ≥2 pages instead of >2
    if (this.numPages >= 2) {
        // Option 1: Move the entire PDF to the target folder
        this.saveAs(targetFolder + this.documentFileName);
        
        // Option 2: Split the PDF into 2-page chunks (if that's what your original script was doing)
        /*
        for (var i = 0; i < this.numPages; i = i + 2) {
            var j = i + 1;
            // Handle the case where the last page is alone (for PDFs with odd page counts)
            if (j >= this.numPages) {
                j = this.numPages - 1;
            }
            var splitDoc = this.extractPages({nStart: i, nEnd: j});
            splitDoc.saveAs(targetFolder + filename + "_pages_" + (i+1) + "-" + (j+1) + ".pdf");
            splitDoc.closeDoc();
        }
        */
    }
} catch (error) {
    console.println("Oops, hit an error: " + error.message);
}

What Changed & Why

  • The Critical Adjustment: Swapped the page count check from this.numPages > 2 to this.numPages >= 2. This tells Acrobat to process any PDF with 2 or more pages, including those exactly 2 pages long.
  • Folder Path Note: Make sure to update targetFolder to your actual destination. For Windows, use double backslashes like C:\\MyPDFs\\Processed\\; for Mac/Linux, use forward slashes like /Users/YourName/Documents/ProcessedPDFs/.
  • Two Options Included:
    • Option 1 is for just moving the entire PDF file to the new folder (simple, if that's all you need).
    • Option 2 keeps the original split-into-2-pages logic (uncomment it if that's what your initial script was doing).

Quick Checks Before Running

  1. Ensure Adobe Acrobat Pro has write permissions to your target folder.
  2. Test with a small set of PDFs first to confirm it works as expected.

内容的提问来源于stack exchange,提问作者Josh Adams

火山引擎 最新活动