【问题标题】:How to split a PDF into multiple documents如何将PDF拆分为多个文档
【发布时间】:2015-03-06 01:30:25
【问题描述】:

我有一个由多个文档组合而成的大型 PDF。

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

【问题讨论】:

    标签: pdf split adobe keyword acrobat


    【解决方案1】:

    除了 Adob​​e Reader,您还需要 Adob​​e Acrobat。

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

    粘贴以下脚本并根据需要进行修改。有关自定义的帮助,请参见 //cmets。

    /* 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++) {
        // DEBUGGING HELP, UNCOMMENT NEXT LINE, CHANGE TO MATCH MULTIPLE WORDS OR WHAT EVER ORDER, eg if ((this.getPageNthWord(p, n) == stringToSearchFor) && (this.getPageNthWord(p, n + 1) == stringToSearchForTWO)) {..., Also add a prompt for the second search word and iterate one less for (var n = 0; n < this.getPageNumWords(p) - 1; n++) ...
        //app.alert("Word is " + this.getPageNthWord(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);
        }
    }
    

    【讨论】:

    • 您实际上需要 Adob​​e Acrobat。 Adobe Reader 将无法运行此脚本,因为它无法插入或提取页面。如果你有 Acrobat,你也会有 Distiller。但是,在这种情况下,我认为 Distiller 没有任何理由。
    • 要记住的另一件事是,PDF 中的“单词”可能与我们在文本中看到的单词不对应。根据用于创建 PDF 的软件,字距调整可能会将 PDF 中的一个单词拆分为多个“单词”。
    • 明天我将使用控制台发布一个脚本,在页面中显示每个 getPageNthWord。感谢您的反馈
    • 可能不需要使用 app.newDoc() 的步骤;提取第一个找到的页面就足够了,然后将这些页面插入到该新文档中。 extractPages() 在成功执行时会返回一个 Doc 对象。这也可以防止任意页面大小可能出现的问题。
    • 最后一条评论......“智能搜索”的一种方法是使用编辑功能(也可以使用正则表达式来查找复杂的单词),然后通过注释,并读出从那里的页码。有点绕道,但更强大......只是不要忘记不要完成编辑,而是在完成后丢弃所有这些注释。
    【解决方案2】:

    请在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());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-08
      • 2022-12-19
      • 2020-05-04
      • 2010-10-04
      • 2013-09-16
      • 2011-04-04
      • 2023-03-03
      • 1970-01-01
      相关资源
      最近更新 更多