Acrobat Javascript Samples Scripts

Introduction:

1. What is Acrobat JavaScript?
2. What can you do with Acrobat JavaScript?
3. Where can I read more about Acrobat JavaScript?
4. How to create a batch sequence with JavaScript code?
5. Sample Acrobat JavaScripts: Introduction

Sample Scripts:

Q & A
What is Acrobat JavaScript?
JavaScript is an object-oriented scripting language developed by Netscape Communications. Acrobat JavaScript implements extensions, in the form of new objects and their accompanying methods and properties, to the JavaScript programming language. These Acrobat-specific objects enable a developer to manipulate a PDF file, allowing the PDF file to communicate with a database, modify its appearance, and so on.
What can you do with Acrobat JavaScript?
Acrobat JavaScript enables you to perform calculations in form fields, respond to user actions, validate user data, modify appearance of Acrobat application, control the behavior of PDF documents, dynamically modify document's appearance and functions, process multiple PDF documents with batch sequences, dynamically create new pages based on template, interface to a database. Acrobat JavaScript code can be executed:
- as an action to respond to user input in the document.
- as document-level script to respond to actions like printing.
- as part of a batch processing sequence that can be applied to multiple files.
Where can I read more about Acrobat JavaScript?
Acrobat JavaScript enables you to do a wide variety of things within a PDF document. The Adobe Solutions Network (ASN) has an Adobe Acrobat JavaScript Training course that covers a wide variety of the possibilities available within Acrobat JavaScript.
Other Acrobat JavaScript documents available from Adobe: Acrobat JavaScript Scripting Guide - provides general introduction into JavaScript programming for Adobe Acrobat. Acrobat JavaScript Object Specification - contains detailed description of all Acrobat specific objects and classes.
How to create a batch sequence with JavaScript code?
The batch processing tool in Adobe Acrobat Pro DC is called Action Wizard. Please see the following tutorial on step-by-step introduction to Action Wizard functionality. Add "Execute JavaScript" tool to the "action" in Action Wizard to run a custom JavaScript code.
Sample Acrobat JavaScripts

Most sample scripts provided on this page are designed to be run inside Action Wizard's "actions". Most scripts have comments in the code that will help you to understand the logic and make any custom modifications. EverMap LLC. provides these scripts for reference only, without warranty of any kind (see disclaimer below). No technical support is provided.
DISCLAIMER: All javascripts on this web site are provided "as is" without warranty of any kind either express or implied, including but not limited to the implied warranty of merchantability and fitness for a particular purpose. The entire risk arising out of the use or performance of these scripts and documentation remains with you.

Create page bookmarks
Description: Automatically creates a bookmark for each page in the document: Page 1, Page 2, Page 3,...
/* 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)
}
Add "Bookmark All Pages" menu to Adobe Acrobat
The code below shows how to add "Bookmark All Pages" 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 / Bookmark All Pages" menu to the Adobe Acrobat. The menu is disabled if there is no PDF document open.
app.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();
}
Delete All Bookmarks
The following single line of code will delete all bookmarks from the current PDF document.
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 to First N-characters
The following script trims all bookmarks to first 10 characters. Adjust this value in the script to get the desired results.
/* 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 and Second Bookmark Levels
The following script combines first level bookmark titles with second level bookmarks, then deletes the second level bookmarks.
/* 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]);
     }

}

Delete Links and Attachments
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();
            }
        }
    }
}
Mark misspelled words
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()
            });
            }
        }
}
Duplicate every page in the document (carbon copy)
Use this script to repeat each page multiple times in the output (1,1,1,2,2,2...). This operation is also known as "carbon copy".
// 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);
}
Extract email addresses
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
Use this script to extract all ISBN numbers from the document into a new PDF file.
/* 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
Extract Social Security Numbers
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
Extract URL addresses
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
Rotate Pages In The Document
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)
}
Rotate Only Landscape/Portrait Pages
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 Navigation Buttons To All Pages
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;
}
Renaming Files Using Bookmark Text
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));

Create Report Document Listing All Bookmarks
The following script creates a report document (in PDF format) that lists all bookmarks in the input PDF file.
function ExtractBookmark(Bm, isRoot)
{
     // write a name of the bookmark     
        var Title = "";

     if (isRoot == false)
     {
          Title += Bm.name;
     }

     // process children
     if (Bm.children != null)
     {     
          for (var i = 0; i < Bm.children.length; i++)
          {     
               if (!(Title === "")) Title += "; " 
               Title += ExtractBookmark(Bm.children[i], false);
          }
     }
     return Title;
}

var root = this.bookmarkRoot;
event.value = ExtractBookmark(root, true);

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);
}