Tips & Tricks

Automating Page Actions

January 12, 2004

Advertisement
Advertisement
 

In a previous tip -- Using Page Actions to Trigger Events in PDFs -- I showed you how to add Actions (either Closing or Opening actions) to a Page in your PDF document. This tip will show you how to add actions to every page in your PDF document - in batch!

I recently published a large PDF document with different sized pages (A4, A2, A0 and even A6!) and what I found was that when I was navigating around the document I had to change the Zoom to suit each page - which quickly became a real pain.

So this tip sets out to solve my problem by adding a Page Action to each page in the PDF document to set the zoom to 100% (Actual) regardless of the current setting. Now normally I wouldn’t recommend this practice however in my case I wanted a consistent page scrolling mechanism.

To accomplish such a feat we need to use a little bit of Javascript that will whip round each page in the PDF check the Width and Height and then add the appropriate Page Action Javascript.

The process is quite straightforward and is outlined as follows:

  1. Enter a Loop based on the Page Count
  2. Add the Javascript to the Page Action for each Page

All that’s required is the following lines of code:


var pageCount = this.numPages;
for(var x = 0;x<pageCount;x++)
{
	setPageAction(x,"Open", "this.zoom = 100;");
}

Note: The reserved words Acrobat uses for built-in properties can often be the first name you want to use when creating variables. Recently I got caught by creating a variable called ‘numPages’ which is of course already in use by Acrobat/Javascript - no error was raised so it took a while before I cottoned on. ;)

To make this script truly useful we can create a new Batch Sequence that can run this javascript against loads of PDF files at once.

From the Advanced Menu choose ‘Batch Processing...’.

Now select ‘New Sequence’ and enter an appropriate name for this sequence.

We need to scroll down the list and find the sequence named: ‘Execute Javascript’, once you’ve clicked ‘Add’ double click the entry on the Right hand panel which will display the Script window. Copy and Paste the Javascript from above (or from the optional code below) into the Window.

Click OK twice, and choose the ‘Browse’ button to set the path on which the Sequence is to operate on. Choose any other Sequence options and select OK. Once your happy with the settings etc, you can ‘Run’ the Sequence.

You’ll also notice if you’ve used the optional code that the bottom of Acrobat indicates the current Page number and the file being operated on.

Optional: I’ve created another version of the Javascript which shows up a progress bar at the bottom indicating the current page number and the file being operated on.


	// Get the Thermometer Object
var thermo = app.thermometer;

var pageCount = this.numPages;

// Set the Max value for the Thermometer
thermo.duration = pageCount;

// Start the Thermometer
thermo.begin();

for(var x = 0;x<pageCount;x++)
{
	// Set some status text in the Thermo
	thermo.text = "[" +this.documentFileName+ "] 
Processing Page: " +(x+1);	
	this.setPageAction(x,"Open", "this.zoom = 100;");

	// Update the Value  in the Thermometer display
	thermo.value = x;
}

// All done
thermo.text = "Processing Complete.";
thermo.end();

To recap we’ve actually touched on three important areas: Batch Sequences, Thermometer and Javascript inside Page Actions. I hope this gives you some food for thought.

Enjoy!

Note: When copy pasting code into the Javascript Window make sure the Quotes are copied as straight quotes and not smart quotes or curly quotes. To correct problems simply change all curly quotes to Straight quotes inside the Javascript Window.

Copyright Dave Wraight & Planet PDF. No unauthorised reproduction, distribution or publication permitted.

Related Products at PDF Store

Nitro PDF Professional

Nitro PDF Professional, your PDF creation and editing product. Priced at $99, Nitro PDF Pro is the m... View full product details
Download free demo

PitStop Professional

The industry standard that combines preflight, interactive editing and automated correction capabili... View full product details
Download free demo

Adobe? Acrobat? & PDF Software

The No.1 PDF and Acrobat software store for tools to create, edit and publish PDF files. Get Nitro P... View full product details
Download free demo

PDF In-Depth Free Product Trials Ubiquitous PDF

Nitro PDF Professional

the perfect PDF product for business and enterprise, combining an extremely competitive price with a...

Download free demo

XpdfViewer

This ActiveX control (OCX) provides a PDF file viewer component, enabling developers to add PDF viewing...

Download free demo

Ubiquitous PDF: PDF eBooks-Library

If you are looking for a good store of PDF content, you could do a lot worse than visiting eBooks-Library.com...

September 03, 2009
Search Planet PDF
more searching options...







Download PDF Creator

Download The Best of Planet PDF volume 2
Planet PDF Newsletter
Most Popluar Articles
Features

Collating PDFs using JavaScript

Despite the numerous benefits, there can be potential issues with the conversion of paper documents into electronic archives. When scanning paper pages into PDF, it's possible to end up with the odd- and even-numbered pages in separate PDF files. It can be very time-consuming to collate them manually, but there is an easier way. Sean Stewart explains.

Featured Product

BCL easyPDF SDK

BCL easyPDF SDK is a set of PDF Programming Libraries designed specifically to help Software Developers / Programmers build and deploy enterprise class PDF applications for corporate wide PDF...

Platinum Sponsor
Create & Edit PDF - Nitro PDF Software

ARTS PDF

Silver Sponsors

PDF-Tools enfocus

QuickPDF: The Unrivaled PDF Developer Toolkit