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.

PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
Platinum Sponsor





Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.

Features

Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.