Batch Find Text and Extract Pages to New PDF

Dear Forum,

I would like to find text and phrases within PDF files and extract pages containing those phrases to new PDF documents. It seems like I should be able to do that with PDF Creator. I have some JavaScript which should be able to perform the work, but I can't get it to function because I can't seem to initialize the correct variables. I was unable to find a knowledgebase on your site containing examples or a JavaScript language reference.

Can you point me to any articles you have, or help me work out my code to perform the required actions? Any help is appreciated! Thanks!

// Set the word to search for here
var sWord = "tillable";

// Source document = current document
var sd = this;
var nWords, currWord, fp, fpa = [], nd;
var fn = sd.documentFileName.replace(/\.pdf$/i, "");

// Loop through the pages
for (var i = 0; i < sd.numPages; i += 1) {

    // Get the number of words on the page
    nWords = sd.getPageNumWords(i);

    // Loop through the words on the page
    for (var j = 0; j < nWords; j += 1) {

        // Get the current word
        currWord = sd.getPageNthWord(i, j);

        if (currWord === sWord) {

            // Extract the current page to a new file
            fp = fn + "_" + i + ".pdf";
            fpa.push(fp);
            sd.extractPages({nStart: i, nEnd: i, cPath: fp});

            // Stop searching this page
            break;
        }
    }
}

// Combine the individual pages into one PDF
if (fpa.length) {

    // Open the document that's the first extracted page
    nd = app.openDoc({cPath: fpa[0], oDoc: sd});

    // Append any other pages that were extracted
    if (fpa.length > 1) {

        for (var i = 1; i < fpa.length; i += 1) {
            nd.insertPages({nPage: i - 1, cPath: fpa[i], nStart: 0, nEnd: 0});
        }
    }

    // Save to a new document and close this one
    nd.saveAs({cPath: fn + "_searched.pdf"});
    nd.closeDoc({bNoSave: true});

}

Dear Forum,

I hope this is not a violation of forum policy, but I am bumping my post. I would really like to use this software, but if I can't get an answer to my question, I won't be able to.

Can anyone help me find out how to make my code work with the software?

Brian

I don't know if you can do what you are asking for with PDFCreator, but you can find some script samples in the PDFCreator installation folder in your pc:
C:\Program Files\PDFCreator\Com Scripts\