如何使用关键字将大型PDF拆分为多个文档

时间:2015-01-08 01:28:37

标签: pdf split

注意:回答我自己的问题作为维基来帮助社区

我有一个从多个文档合并的大型PDF。

如何使用关键字分隔符将PDF拆分为多个文档?

2 个答案:

答案 0 :(得分:2)

除Adobe Reader外,您还需要Adobe Acrobat。

使用操作向导添加以下脚本:

enter image description here

enter image description here

/* Extract Pages into Documents by Keyword */
// Iterates over all pages and find a given string and extracts all 
// pages on which that string is found to a new file.

var pageArray = [];
var pageArrayEnd = [];

var stringToSearchFor = app.response("This Action Script splits the document by a keyword on each X number of pages, please enter the keyword:");

for (var p = 0; p < this.numPages; p++) {
    // iterate over all words
    for (var n = 0; n < this.getPageNumWords(p); n++) {
        if (this.getPageNthWord(p, n) == stringToSearchFor) {
            //app.alert("Found word on page " + p + " word number " + n, 3);
            if (pageArray.length > 0) {
                pageArrayEnd.push(p - 1);
            }
            pageArray.push(p);
            break;
        }
    }
}

pageArrayEnd.push(this.numPages - 1);
//app.alert("Number of sub documents " + pageArray.length, 3);
if (pageArray.length > 0) {
    // extract all pages that contain the string into a new document
    for (var n = 0; n < pageArray.length; n++) {
        var d = app.newDoc();    // this will add a blank page - we need to remove that once we are done
            //app.alert("New Doc using pages " + pageArray[n] + " to " + pageArrayEnd[n], 3);
            d.insertPages( {
                            nPage: d.numPages-1,
                            cPath: this.path,
                            nStart: pageArray[n],
                            nEnd: pageArrayEnd[n],
            } );
        // remove the first page
        d.deletePages(0);
        d.saveAs({ cPath: this.path.replace(".pdf","") + n + ".pdf" });
        d.closeDoc(true);
    }
}

答案 1 :(得分:0)

请在how to split PDF into multiple file上查看本指南:

// Used to register all DLL assemblies.
WorkRegistry.Reset();

String inputFilePath = Program.RootPath + "\\" + "1.pdf";
String outputFileName = "Output";
int[] splitIndex = new int[3] { 1, 3, 5 }; // Valid value for each index: 1 to (Page Count - 1).

// Create output PDF file path list
List<String> outputFilePaths = new List<String>();
for (int i = 0; i <= splitIndex.Length; i++)
{
        outputFilePaths.Add(Program.RootPath + "\\" + outputFileName + "_" + i.ToString() + ".pdf");
}

// Split input PDF file to 4 files:
// File 0: page 0.
// File 1: page 1 ~ 2.
// File 2: page 3 ~ 4.
// File 3: page 5 ~ the last page.
PDFDocument.SplitDocument(inputFilePath, splitIndex, outputFilePaths.ToArray());