javascript AdobeAcrobat Javascripts

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript AdobeAcrobat Javascripts相关的知识,希望对你有一定的参考价值。

/* Create bookmarks for each page in the document */
var root = this.bookmarkRoot;
try {

    for (var i = 0; i < this.numPages; i++)
       {
       root.createChild("Page " + (i+1), "this.pageNum=" + i, i);
       }
} 
catch(e)
{
app.alert("Processing error: "+e)
}
pp.addMenuItem({ cName: "&Bookmark Every Page", cParent: "Extensions",
cExec: "BookmarkAllPages();",
cEnable: "event.rc = (event.target != null);",
nPos: 0
});

function BookmarkAllPages()
{
var t = app.thermometer;
t.duration = this.numPages;
t.begin();

     /* Create bookmarks for each page in the document */
     var root = this.bookmarkRoot;
     try {

          for (var i = 0; i < this.numPages; i++)
          {
               t.value = i;
               t.text = "Processing page " + (i + 1);
               if (t.cancelled) break;
               root.createChild("Page " + (i+1), "this.pageNum=" + i, i);
          }
     } 
     catch(e)
     {
     app.alert("Processing error: "+e)
     }
t.end();
}
this.bookmarkRoot.remove();
//The code below shows how to add "Delete All Bookmarks" menu to the 
//Adobe Acrobat interface. Save this code with *.js file extension and 
//place it into JavaScripts folder under Adobe Acrobat installation. 
//For example, for Acrobat DC this folder is located in 
//C:\Program Files (x86)\Adobe\Acrobat 2017\Acrobat\JavaScripts\. 
//It will add "Plug-ins / Delete All Bookmarks" menu to the Adobe Acrobat. 
//The menu is disabled if there is no PDF document open.
app.addMenuItem({ cName: "&Delete All Bookmarks", cParent: "Extensions",
cExec: "this.bookmarkRoot.remove();",
cEnable: "event.rc = (event.target != null);",
nPos: 0
});
/* Trim Bookmark Titles */

function TrimBookmarkTitle(NumChars, Bm, nLevel)
{
    var nLevelMax = 2; // change maximum level of the processed bookmarks, starts from 0
    if (nLevel > nLevelMax)
    {
        return;
    }

    var Title = new String(Bm.name);
    Bm.name = Title.substr(0, NumChars); // set bookmark title to first NumChars characters
    // Uncomment one of the following lines for a desired action
    // Bm.name = Title.substr(-NumChars,NumChars); // set bookmak title to last NumChars
    // Bm.name = Title.slice(NumChars,Title.length); // trims first NumChars from the bookmark
    // Bm.name = Title.slice(0,-NumChars); // trims last NumChars from the bookmark
    
    // process children
    if (Bm.children != null)
    {     
     for (var i = 0; i < Bm.children.length; i++)
     {     
          TrimBookmarkTitle(NumChars, Bm.children[i], nLevel + 1);
     }     
    }
}

var root = this.bookmarkRoot;
var NumCharsToTrimTo = 10; // trim bookmark title to the first 10 characters
TrimBookmarkTitle(NumCharsToTrimTo, root, 0);
/* Merge first level bookmark titles with second level bookmarks, delete second level bookmark */
function MergeTitles(Bm)
{
     if (Bm.children != null)
     {     
          Bm.name = Bm.name + " " + Bm.children[0].name;
          Bm.children[0].remove();
     }
}

var root = this.bookmarkRoot;
if (root.children != null)
{     
     for (var i = 0; i < root.children.length; i++)
     {     
          MergeTitles(root.children[i]);
     }

}
/* The following script deletes all links and file attachments from the current PDF file.
/* Delete All Links and File Attachments */
this.syncAnnotScan();
var numpages = this.numPages;
for (var i=0; i < numpages; i++) 
{
    var annots = this.getAnnots( { nPage:i});
    if (annots != null)
    {
        for (var j = annots.length - 1; j >= 0 ; j--)
        {
            if (annots[j].type == "Link" || annots[j].type == "FileAttachment")
            {
                annots[j].destroy();
            }
        }
    }
}
/* The code below spellchecks every word in the document and marks misspelled ones with a squiggle annotation.
/* Mark misspelled words with squiggle */
var chWord, numWords;
for (var i = 0; i < this.numPages; i++)
{
    numWords = this.getPageNumWords(i);
    for (var j = 0; j < numWords; j++) {
        ckWord = spell.checkWord(this.getPageNthWord(i,j))
        if (ckWord != null) {
            this.addAnnot({
                page: i,
                type: "Squiggly",
                quads: this.getPageNthWordQuads(i,j),
                author: "A.C.Acrobat",
                contents: ckWord.toString()
            });
            }
        }
}
// Carbon Copy pages in the PDF file 
// IMPORTANT: Set Output Options to the filename you need

// CHANGE THIS NUMBER: IT'S NUMBER OF ADDITIONAL COPIES 
var nNumCopies = 2; // make 1 additional copy(es) of each page

try {

var newName = this.path;
var filename = newName.replace(".pdf","_Original.pdf"); // save a copy of original document
this.saveAs(filename);

var Num = this.numPages;
var nNumDups = nNumCopies+1; 

for (var i = 0; i < Num; i++) {
    for (var j = 0; j < nNumCopies; j++) {
        k = i*nNumDups + j;
        this.insertPages({ nPage: k, cPath:newName, nStart:i });
        }
    }

// set page labels: number each copy with a label
for (var k = 0; k < this.numPages; k+= nNumDups) 
{
     this.setPageLabels(k,[ "D", "Copy ", 1]);   
}

}
catch(e)
{
    app.alert(e);
}
Use this script to extract all email addresses into a new PDF file.
// This script will scan all pages of the input document
// and extract valid email addresses into new PDF document
// Output PDF document will be placed in the same folder
// as input. The name of the output document will be:
// Original filename + "_Extracted_Emails"
// Visit www.evermap.com for more useful JavaScript samples.

var reEmail = /(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/g;

var strExt = "_Extracted_Emails.pdf";
var strIntro = "Email addresses extracted from document: ";
var strFinal = "Total number of email addresses extracted: " ;

ExtractFromDocument(reEmail,strExt,strIntro,strFinal);

function ExtractFromDocument(reMatch, strFileExt, strMessage1, strMessage2)
{
var chWord, numWords;

// construct filename for output document
var filename = this.path.replace(/\.pdf$/, strFileExt);

// create a report document
try {
    var ReportDoc = new Report();
    var Out = new Object(); // array where we will collect all our emails before outputing them
    
    ReportDoc.writeText(strMessage1 + this.path);
    ReportDoc.divide(1);      // draw a horizontal divider
    ReportDoc.writeText(" "); // write a blank line to output
    var nTotal = 0;
    var nCounter = 0;
    var nLinesPerPages = 60;

    for (var i = 0; i < this.numPages; i++)
    {
        numWords = this.getPageNumWords(i);
        var PageText = "";
        for (var j = 0; j < numWords; j++) {
            var word = this.getPageNthWord(i,j,false);
            PageText += word;
            }
    
        var strMatches = PageText.match(reMatch);
        if (strMatches == null) continue;
        // now output matches into report document
        for (j = 0; j < strMatches.length; j++) 
        {
            ReportDoc.writeText(strMatches[j]);
            nTotal++;
            nCounter++;
            if (nCounter > nLinesPerPages)
            {
                ReportDoc.breakPage();
                nCounter= 0;
            }
        }
    }
    
    ReportDoc.writeText(" "); // output extra blank line
    ReportDoc.divide(1); // draw a horizontal divider
    ReportDoc.writeText(strMessage2 + nTotal);
    
    // save report to a document
    ReportDoc.save(
        {
        cDIPath: filename
        });

}
catch(e)
{
app.alert("Processing error: "+e)
}
    
} // end of the function
/* Extract ISBN numbers From the Document */
// This script will scan all pages of the input document
// and extract valid ISBN numbers into new PDF document.
// Output PDF document will be placed in the same folder
// as input. The name of the output document will be:
// Original filename + "_Extracted_ISBN"
// Visit www.evermap.com for more useful JavaScript samples.

// This is a combination of strict and relaxed versions of ISBN number format
var reISBN=/(ISBN[\:\=\s][\s]*(?=[-0-9xX ]{13})(?:[0-9]+[- ]){3}[0-9]*[xX0-9])|(ISBN[\:\=\s][ ]*\d{9,10}[\d|x])/g;

var strExt = "_Extracted_ISBN.pdf";
var strIntro = "ISBN numbers extracted from document: ";
var strFinal = "Total number of ISBN numbers extracted: " ;

ExtractFromDocument(reISBN,strExt,strIntro,strFinal);

function ExtractFromDocument(reMatch, strFileExt, strMessage1, strMessage2)
{
var chWord, numWords;

// construct filename for output document
var filename = this.path.replace(/\.pdf$/, strFileExt);

// create a report document
try {
    var ReportDoc = new Report();
    var Out = new Object(); // array where we will collect all our emails before outputing them
    
    ReportDoc.writeText(strMessage1 + this.path);
    ReportDoc.divide(1);      // draw a horizontal divider
    ReportDoc.writeText(" "); // write a blank line to output
    
    for (var i = 0; i < this.numPages; i++)
    {
        numWords = this.getPageNumWords(i);
        var PageText = "";
        for (var j = 0; j < numWords; j++) {
            var word = this.getPageNthWord(i,j,false);
            PageText += word;
            }
    
        var strMatches = PageText.match(reMatch);
        if (strMatches == null) continue;
        // now output matches into report document
        for (j = 0; j < strMatches.length; j++) {
            Out[strMatches[j]] = true; // store email as a property name
            }
    }
    
    var nTotal = 0;
    for (var prop in Out) 
    {
        ReportDoc.writeText(prop);
        nTotal++;
    }
    
    ReportDoc.writeText(" "); // output extra blank line
    ReportDoc.divide(1); // draw a horizontal divider
    ReportDoc.writeText(strMessage2 + nTotal);
    
    // save report to a document
    ReportDoc.save(
        {
        cDIPath: filename
        });

}
catch(e)
{
app.alert("Processing error: "+e)
}
    
} // end of the function
Use this script to extract all SSN numbers from the document into a new PDF file.
/* Extract US Social Security Numbers From the Document */
// This script will scan all pages of the input document
// and extract :
// Social security numbers: 
// Output PDF document will be placed in the same folder
// as input. The name of the output document will be:
// Original filename + "_Extracted_SSNs"
// Visit www.evermap.com for more useful JavaScript samples.

var reMatch=/(?!000)([0-6]\d{2}|7([0-6]\d|7[012]))([ -])(?!00)\d\d\3(?!0000)\d{4}/g;

var strExt = "_Extracted_SSNs.pdf";
var strIntro = "Social Security Numbers extracted from document: ";
var strFinal = "Total number of SSNs extracted: " ;

ExtractFromDocument(reMatch,strExt,strIntro,strFinal);

function ExtractFromDocument(reMatch, strFileExt, strMessage1, strMessage2)
{
var chWord, numWords;

// construct filename for output document
var filename = this.path.replace(/\.pdf$/, strFileExt);

// create a report document
try {
    var ReportDoc = new Report();
    var Out = new Object(); // array where we will collect all our emails before outputing them
    
    ReportDoc.writeText(strMessage1 + this.path);
    ReportDoc.divide(1);      // draw a horizontal divider
    ReportDoc.writeText(" "); // write a blank line to output
    
    for (var i = 0; i < this.numPages; i++)
    {
        numWords = this.getPageNumWords(i);
        var PageText = "";
        for (var j = 0; j < numWords; j++) {
            var word = this.getPageNthWord(i,j,false);
            PageText += word;
            }
        var strMatches = PageText.match(reMatch);
        if (strMatches == null) continue;
        // now output matches into report document
        for (j = 0; j < strMatches.length; j++) {
            Out[strMatches[j]] = true; // store email as a property name
            }
    }
    
    var nTotal = 0;
    for (var prop in Out) 
    {
        ReportDoc.writeText(prop);
        nTotal++;
    }
    
    ReportDoc.writeText(" "); // output extra blank line
    ReportDoc.divide(1); // draw a horizontal divider
    ReportDoc.writeText(strMessage2 + nTotal);
    
    // save report to a document
    ReportDoc.save(
        {
        cDIPath: filename
        });

}
catch(e)
{
app.alert("Processing error: "+e)
}
    
} // end of the function
Use this script to extract all URL addresses (http,https,ftp,www...) from the document into a new PDF file.
/* Extract URLs (Web Addresses) From the Document */
// This script will scan all pages of the input document
// and extract :
// Valid URL s -- allows http, https, ftp, ftps and simple www.mydomain...
// Output PDF document will be placed in the same folder
// as input. The name of the output document will be:
// Original filename + "_Extracted_URLs"
// Visit www.evermap.com for more useful JavaScript samples.

var reMatch=/((((ht|f)tp(s?))\:\/\/)|(www.))([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?/g;
//var reMatch=/(((ht|f)tp(s?))\:\/\/).*/g;

var strExt = "_Extracted_URLs.pdf";
var strIntro = "URLs (http,https,ftp,ftps) extracted from document: ";
var strFinal = "Total number of URLs (web addresses) extracted: " ;

ExtractFromDocument(reMatch,strExt,strIntro,strFinal);

function ExtractFromDocument(reMatch, strFileExt, strMessage1, strMessage2)
{
var chWord, numWords;

// construct filename for output document
var filename = this.path.replace(/\.pdf$/, strFileExt);

// create a report document
try {
    var ReportDoc = new Report();
    var Out = new Object(); // array where we will collect all our emails before outputing them
    
    ReportDoc.writeText(strMessage1 + this.path);
    ReportDoc.divide(1);      // draw a horizontal divider
    ReportDoc.writeText(" "); // write a blank line to output
    
    for (var i = 0; i < this.numPages; i++)
    {
        numWords = this.getPageNumWords(i);
        var PageText = "";
        for (var j = 0; j < numWords; j++) {
            var word = this.getPageNthWord(i,j,false);
            PageText += word;
            }

        var strMatches = PageText.match(reMatch);
        if (strMatches == null) continue;
        // now output matches into report document
        for (j = 0; j < strMatches.length; j++) {
            Out[strMatches[j]] = true; // store email as a property name
            }
    }
    
    var nTotal = 0;
    for (var prop in Out) 
    {
        ReportDoc.writeText(prop);
        nTotal++;
    }
    
    ReportDoc.writeText(" "); // output extra blank line
    ReportDoc.divide(1); // draw a horizontal divider
    ReportDoc.writeText(strMessage2 + nTotal);
    
    // save report to a document
    ReportDoc.save(
        {
        cDIPath: filename
        });

}
catch(e)
{
app.alert("Processing error: "+e)
}
    
} // end of the function
//The following script rotates all pages in the document.
/* Rotate all pages (or page range) in the document */

// Modify nStart, nEnd and nRotate to change script logic

nStart = 0 // first page to rotate
nEnd = this.numPages - 1; // last page to rotate
nRotate = 90 // allowed rotations: 0, 90, 180, 270

try {
     if (this.numPages > 0) {     
           this.setPageRotations(nStart,nEnd,nRotate)
           }
} 
catch(e)
{
app.alert("Processing error: "+e)
}
Use this script to rotate only landscape or portrait pages in the PDF document.
/* Rotate only landscape or portrait pages in the document */

// Modify nStart, nEnd and nRotate to change script logic

nStart = 0; // first page to rotate
nEnd = this.numPages - 1; // last page to rotate
nRotate = 0; // allowed rotations: 0, 90, 180, 270
bLanscape = true; // set to false to process only Portrait pages

try {

    for (var i = nStart; i <= nEnd; i++)
       {
       // check if this page is landscape or portrait
       var aRect = this.getPageBox("Media",i);
       var Width = aRect[2] - aRect[0];
       var Height = aRect[1] - aRect[3];
       if (Height > Width) { // portrait
     if (!bLandscape) {
          this.setPageRotations(i,i,nRotate)
          }
     }
       else { // landscape
     if (bLandscape) {
             this.setPageRotations(i,i,nRotate)
        }
                }
       }
} 
catch(e)
{
app.alert("Processing error: "+e)
}
Delete Pages Without Text
Use this code to delete pages from the document that contain no text elements. Note that if the PDF file is a scanned paper document, then pages in such file might not contain any text elements.
// Acrobat JavaScript Code - www.evermap.com
// DELETE PDF PAGES WITHOUT TEXT 
// IMPORTANT: This script assumes that page is blank if it does not contain any "pdf words"
// OUTPUT: An output PDF file is created by appending _Original.pdf to the filename

try {
     var newName = this.path;
     var filename = newName.replace(".pdf","_Original.pdf"); 
     this.saveAs(filename);
     for (var i = 0; i <  this.numPages; i++) 
     {
          numWords = this.getPageNumWords(i);
          if (numWords == 0) 
          {
               // this page has no text, delete it
               this.deletePages(i,i);
          }
     }
}
catch(e)
{
    app.alert(e);
}
Add "Previous Page", "First Page" and "Next Page" and "Go Back To Previous View" navigation buttons to the top of every page in the document. Contain simple function for creating a button, illustrates how to set button attributes, size, action and tooltip. Customize this script to create desired button appearance and behavior.
// Add navigation buttons to the page
// This script puts 3 buttons on top of every page (except the first one that has one button)
// First button "<" : takes to the previous page
// Second button: "1" : takes to the first page of the document
// Third button: ">" : takes to the next page in the document (does not exists on the last page)

var inch = 72;

try 
{

    nLastPage = this.numPages - 1;

    for (var p = 0; p < this.numPages; p++)
    {
        var x = 0.5;
 
        if (p > 0)
        {
            AddButton(p,x,0.5,0.25,0.25,"PrevPage","<","Previous Page","this.pageNum--;"); // left arrow, previous page
            x += 0.3;
        }
    
        if (p != 0)
        {
            AddButton(p,x,0.5,0.25,0.25,"StartPage","1","Go To First Page","this.pageNum=0;"); // "1", takes to the first page
            x += 0.3;
        }
    
        if (p < nLastPage)
        {
            AddButton(p,x,0.5,0.25,0.25,"NextPage",">","Next Page","this.pageNum++;"); // right arrow, next page
            x += 0.3;
        }

        AddButton(p,x,0.5,0.25,0.25,"Back","<<","Go Back","app.execMenuItem(\"GoBack\");"); // right arrow, next page
        x += 0.3;
        
    }

}


catch (e)
{
app.alert(e);
}

// AddButton function creates a button with given parameters and action

function AddButton(nPageNum, x, y, width, height, strText, strCaption, strToolTip, strAction)
{
    var aRect = this.getPageBox( { nPage: nPageNum} );
    aRect[0] += x * inch;
    aRect[1] -= y * inch;
    aRect[2] = aRect[0] + width * inch;
    aRect[3] = aRect[1] - height * inch;

    var f = this.addField(strText,"button", nPageNum, aRect);
    f.setAction("MouseUp",strAction);
    f.userName = strToolTip;
    f.delay = true;
    f.borderStyle = border.s;
    f.highlight = "push";
    f.textSize = 0; // autosized
    f.textColor = color.blue;
    f.strokeColor = color.blue;
    f.fillColor = color.white;
    // you can specify a different font here, otherwise it uses a default one
    //f.textFont = font.ZapfD;
    f.buttonSetCaption(strCaption); 
    f.delay = false;
}
Use this script as an example on how to use bookmark titles to rename files. This script takes first 3 bookmarks and creates a custom filename that is used to save a file.
/* Rename Files Using Bookmarks */
// This is a script that can rename files based on bookmarks. 
// If document has 3 bookmarks the output filename is:
// First bookmark From Second Bookmark – Third Bookmark
// If there are more than 3 bookmarks, then output filename is:
// First bookmark From Second Bookmark To Third Bookmark – Forth Bookmark 

var fname = "";
var bm = this.bookmarkRoot;

// build a name
if (bm.children != null)
{        
        var numBookmarks = Math.min(4,bm.children.length);
     for (var i = 0; i < numBookmarks; i++)
     {
          switch (i) 
                {
                    case 1:
                        fname += " From ";
                        break;
                    case 2:
                        if (numBookmarks > 3)
                        {
                            fname += " To ";
                        }
                        else
                        {
                            fname += " - ";
                        }
                        break;
                    case 3:
                        fname += " - ";
                        break;
                    
                }
          fname += bm.children[i].name;
     }
}

// make sure no illegal characters are included in the filename
var outputname = fname.replace(/[?:\\/|<>"*]/g,"_");

// console.println(outputname);

// save document into c:/data/ folder
// IMPORTANT: replace with a desired output folder location
this.saveAs("/c/data/" + outputname + ".pdf");
Saving Files With Time Stamp In The Filename
The following script creates unique names for documents based on a current time. This script does not overwrite existing files.
/* Save files with a timestamp filename */
/* this script does not overwrite existing files - unique names are created */
/* EverMap LLC, 2009 */

function DoesFileExists(pathname)
{
    var result = false;
    try
    {
        var otherDoc = app.openDoc(pathname);
        if (otherDoc != null)
        {
            result = true;
            otherDoc.closeDoc();
        }
    }
    catch(e)
    {
        result = false; 
    }
    return result;
}

// create a unique filename for output file
function GetUniqueOutputFileName(pathName)
{
    var i = 1; 
    var baseName = pathName.slice(0, pathName.length - 4);
    var testName = pathName;
    while (DoesFileExists(testName) == true)
    {
        testName = baseName + " " + i + ".pdf";
        i++;
    }
    return testName;
}

var i = this.path.search(/[^:/]+\.pdf$/);
var fname = this.path.slice(i, this.path.length - 4);

// replace /c/data/ with a desired folder path where to store extracted files
var folder = "/c/data2/";

// now add time stamp data to the filename
var t = new Date();
fname += " - " + t.toLocaleString();
var outputname = fname.replace(/[,\\/\?*<>]/g," ");
outputname = outputname.replace(/[:]/g,"-");

var outputpath = folder + outputname + ".pdf";
this.saveAs(GetUniqueOutputFileName(outputpath));
The following script creates a report document (in PDF format) that lists all bookmarks in the input PDF file.
/* Create a bookmark report */

function PrintBookmark(Report, Bm, nLevel)
{

     // write a name of the bookmark     
        var inch = 72;  
     Report.writeText(Bm.name);

     // process children
     if (Bm.children != null)
     {     
          Report.indent(inch/2);
          for (var i = 0; i < Bm.children.length; i++)
          {     
               PrintBookmark(Report, Bm.children[i], nLevel + 1);
          }
          Report.outdent(inch/2);
     }
}

var root = this.bookmarkRoot;
var Report = new Report();
PrintBookmark(Report, root, 0);

// Change output path for the report
Report.save("/c/myreport.pdf");
Convert StrikeOuts to Highlights
Description: Convert all strike-out annotations to highlight annotations on all pages of the document.
// This script converts all StrikeOut (cross-out) annotations into Highlights
// The similar approach can be used to convert between all 3 text markup
// annotations types: Highlights, Underline and CrossOut

try
{
     this.syncAnnotScan();
     for (var nPage = 0; nPage < this.numPages; nPage++)
     {
          // get all annotations on the page
          var Annots = this.getAnnots({
               nPage:nPage
               });
          // process each annotation
               if (Annots != null)
              {
                   for (var i = 0; i < Annots.length; i++)
                   {
                        if (Annots[i].type == "StrikeOut")
                        {
                             Annots[i].type = "Highlight";
                        }
                   }
              }
     }
}
catch(e)
{
     app.alert(e);
}
AutoBookmark
Create and edit PDF bookmarks, links & TOC
AutoMailMerge
Populate PDF forms from data files
AutoSplit
Split, merge and rename PDF files
AutoPortfolio
Email-to-PDF conversion: Convert PDF portfolios
AutoDocSearch
Organize PDF files into Folders By Text Search
AutoInk
Write, draw and fill forms using pen input
AutoDocMail
Automatically email PDF documents via text search
AutoRedact
Redact text and images in PDF documents
AutoBatch
Execute Acrobat actions from command-line scripts
AutoPagex
Advanced page editing tools for Adobe Acrobat
AutoMassSecure
Secure PDF files with individual passwords
AutoMetadata
Free PDF metadata editing software
/* Extract PDF based on Content */
 
// Initialize an array that will hold all the page values
var pageArray = [];

// Initialize the search string   ΜΑΛΑΘΥΡΟΥ   "ΜΑΛΑΘΥΡΟΥ";  ÊÉÓÓÁÌÏÕ
var stringToSearchFor = "ΜΑΛΑΘΥΡΟΥ";
//stringToSearchFor = app.response("Enter search word");


// Initialize default save path
var defaultpath = "z:\\cut_pdfs\\"

// Initialize input filename and remove .pdf suffix 
var inputfilename = this.documentFileName.replace(/.pdf/,"")
var addendum = ".scanned"
var suffix = ".pdf"
var fullsuffix = addendum.concat(suffix)

// Construct  output file name
var outputfilename = inputfilename.concat(fullsuffix)

// Construct full output path
var foutpath = defaultpath.concat(outputfilename)

//app.alert(stringToSearchFor, 3);
//app.alert(inputfilename, 3);
//app.alert(outputfilename, 3);
//app.alert(foutpath, 3);

// Iterate over all pages
for (var p = 0; p < this.numPages; p++) {
    
    // Iterate over all the words of the page
    for (var n = 0; n < this.getPageNumWords(p); n++) {
        
        // Perform check
        //if (this.getPageNthWord(p, n) == stringToSearchFor)
        if ( (this.getPageNthWord(p, n)).indexOf(stringToSearchFor) >= 0 )
        {
       
            //app.alert("FOUND MATCH", 3)
            
            // Add page index to array
            pageArray.push(p);

            //app.alert(pageArray, 3);

            // Break from loop.
            break;
        }
    }
}

// Iterate over page array
if (pageArray.length > 0) {
    
    // extract all the pages that contain string into a new document
    var d = app.newDoc();

    // Iterate over page array
    for (var n = 0; n < pageArray.length; n++ ) {


        //app.alert("Inserting page")
        d.insertPages( {
            nPage: d.numPages - 1,
            cPath: this.path,
            nStart: pageArray[n],
            nEnd: pageArray[n],
        
        });
        //app.alert("Finished inserting page");

    }

    // remove the first page
    d.deletePages(0);

    //}
    //d.saveAs(foutpath)


    d.saveAs(foutpath)
    d.closeDoc()

}
/* Extract PDF based on Content */
 
// Initialize an array that will hold all the page values
var pageArray = [];

// Initialize the search string
//var stringToSearchFor = "ΦΥΤΡΟΥ";
var stringToSearchFor = app.response("Enter search word");

// Initialize default save path
var defaultpath = "z:\\cut_pdfs\\"

// Initialize input filename and remove .pdf suffix 
var inputfilename = this.documentFileName.replace(/.pdf/,"")
var addendum = ".scanned"
var suffix = ".pdf"
var fullsuffix = addendum.concat(suffix)

// Construct  output file name
var outputfilename = inputfilename.concat(fullsuffix)

// Construct full output path
var foutpath = defaultpath.concat(outputfilename)

//app.alert(stringToSearchFor, 3);
//app.alert(inputfilename, 3);
//app.alert(outputfilename, 3);
//app.alert(foutpath, 3);

// Iterate over all pages
for (var p = 0; p < this.numPages; p++) {
    
    // Iterate over all the words of the page
    for (var n = 0; n < this.getPageNumWords(p); n++) {
        
        // Perform check
        if (this.getPageNthWord(p, n) == stringToSearchFor) {
            
            // Add page index to array
            pageArray.push(p);

            //app.alert(pageArray);

            // Break from loop.
            break;
        }
    }
}

// Iterate over page array
if (pageArray.length > 0) {
    
    // extract all the pages that contain string into a new document
    var d = app.newDoc();

    // Iterate over page array
    for (var n = 0; n < pageArray.length; n++ ) {


        //app.alert("Inserting page")
        d.insertPages( {
            nPage: d.numPages - 1,
            cPath: this.path,
            nStart: pageArray[n],
            nEnd: pageArray[n],
        
        });
        //app.alert("Finished inserting page");

    }

    // remove the first page
    d.deletePages(0);

    //}
    //d.saveAs(foutpath)


    d.saveAs(foutpath)


}

以上是关于javascript AdobeAcrobat Javascripts的主要内容,如果未能解决你的问题,请参考以下文章

acrobat 怎么让这个窗口不显示?

adobeacrobat勾画好的笔记如何保存

面试中的JavaScript之函数对象数组.md

adobe acrobat pro怎么激活

asp.net将PDF文件转换成图片,并且在网页上显示

javascript 冒泡排序