Translate
Francais Español Deutsch
 
 
   
Developers Product Chooser PDF Choosing Wizard Feature Comparison Chart Image Product Chooser Image Comparison Chart

Do it all with PDF-XChange PRO

A product suite that includes all of the above PDF products and allows you to do pretty much whatever you want with PDFs

PRO PDF

PDF-XChange Viewer

PDF-XChange Lite

PDF-XChange Standard

PDF-Tools

Imaging Products


Raster-XChange


Tiff-XChange

SDKs for PDFs: SDKs for Imaging: Clarion® SDKs:

PDF Related

Imaging Products

Clarion® Developers now have the choice of using our generic SDKs, or downloading our Clarion® specific SDKs which include extra Clarion® classes, templates and examples for fast and easy integration into their Clarion® based applications.
Knowledgebase

Knowledgebase

How do I use JavaScript in the Viewer?

Knowledge Base Article: KB355 - Created On: Jan 11, 2012 03:11 PM - Last Modified: May 2, 2012 06:23 AM

 
Symptoms

 I want to use JavaScript to perform an action on a PDF but I can't find how to do that.

 

Cause

 The JavaScript console is only accessible through the keyboard shortcut CTRL+J

 

Resolution

There area number of actions that can be performed on a PDF document using JavaScript. 

To do so simply

  • launch the JavaScript console with CTRL+J
    Java Script Console
     
  • paste or write your JavaScript code into the top of the two windows:

    JSConsole with code
     
  • Click the "Run" button

    JSConsole Run
     
  • The code will run and errors messages will be displayed in the box below your code. 

In the sample above the script reverses the page order by iterating through the document and changing the page numbers.  The 'undefined' output is when the script comes to the end of the document.  We could write JS code that would stop that happening but in this case it was not needed.


Examples

Iterate through a PDF and reverse the order of the pages.

for (i = this.numPages - 1; i >= 0; i--) this.movePage(i);

 

Check if a document contains bookmarks

function HasBookmarks(document)
{
  return (document.bookmarkRoot.children != null) && (document.bookmarkRoot.children.length > 0);
}
HasBookmarks(this);

it returns string "true" if there are bookmarks, and "false" otherwise.

 

 

Vote

Was this article helpful?

More Like This

   KB#255: How do I customize the file name used when creating PDF files sent from a specific application?

   KB#46: How do I post a support request to the forum

   KB#279: I have a problem with copying text from a PDF document.

   KB#146: How do I create custom short cut keys for tool bar commands?

   KB#145: How do I use 2 page facing when in full screen mode?