TIP: How to insert Document-level JavaScripts into a PDF file using a "dummy" PDF file
Used with his latest interactive math quiz

EDITOR'S NOTE - 10 May 2001: See Dr. Story's updated version of this technique for Acrobat 5.0.

This tip was submitted by Prof. D. P. Story of the University of Akron Dept. of Mathematics and Computer Science, who added that he worked out this AcroTip while working on this JavaScript for his latest interactive math quiz, which makes heavy use of document-level JavaScripts.

"This method is very convenient for revising the quiz questions and reintroducing the JavaScript," he says.

BACKGROUND:

I have created several PDF games (and other PDF documents) using TeX that use Document-level JavaScripts.

Now, TeX is a macro-based typesetting system; the source file is compiled, then converted into a PostScript file. Using the macro feature, raw postscript can be written to this file, in this way, links and forms can be defined using the pdfmark operator and written to the postscript file.

Document-level JavaScripts cannot, at this time, be written to the postscript file using the pdfmark paradigm. Normally, I must create the PostScript file, distill, then open the PDF file in Acrobat and copy and paste my JavaScripts into the code window for Document- level JavaScripts. Any modification to the source file and rebuilding of the PDF file requires that again I must copy and paste the JavaScripts back into the file.

THE PROBLEM:

Suppose you have one or more files into which you want to insert the same Document-level JavaScript (consisting of one or more functions). A relatively efficient method of doing this is described below.

THE METHOD:

In the steps that follow, target.pdf refers to the name of one of the files into which you want to insert Document-level JavaScript.

Step 0 -- Create a dummy.pdf file (perhaps using the filenew.api plugin to create an empty PDF document). Now, insert your Document-level JavaScripts into this document using the Acrobat interface. Save and Close.

Step 1 -- Load your target.pdf file into Acrobat.

Step 2 -- Choose "Document > Insert Pages..." from the Acrobat menu.

Step 3 -- Select the dummy.pdf file, the one which contains the Document level JavaScripts you want to insert into the target.pdf file.

Step 4 -- In the "Insert Pages..." dialog box, choose to insert your dummy page BEFORE the FIRST page of the target document. Click on "Ok".

Step 5 -- Now choose "Document > Delete Pages ...." from the Acrobat menu.

Step 6 -- Set the "Delete Pages ..." dialog box to "From 1 to 1" (assuming your dummy.pdf file had only one page), Click on "Ok".

Step 7 -- Save the target.pdf document that is still open in Acrobat.

Done! Now, the target.pdf file contains the Document-level JavaScripts.

REMARKS:

  1. The open/close page actions of the target document are preserved by this insertion and deletion process.
  2. This procedure would work well for a small collection of documents that are undergoing revision and with each revision the JavaScripts must be reintroduced. Just maintain a "script" document (this script document can contain documentation of the JavaScript itself) and invoke this insert/delete procedure.
  3. For larger collections of PDF files, automation is necessary. I have written a small VBA to carry out this procedure. However, this procedure is probably less efficient than using the forms api method AddDocJavaScript directly.

By the way, this method makes it very convenient to distribute general purpose JavaScripts and to "load" them into your document. For this reason, there a slight commercial value to this method.
PDF In-Depth Free Product Trials Ubiquitous PDF

Pitstop Pro

Now graphic arts professionals have even broader and more expert control over their PDF documents. With...

Download free demo

ARTS PDF Aerialist

The ultimate plug-in for Adobe Acrobat and #1 selling product at PDF Store. Advanced splitting, merging,...

Download free demo

Ubiquitous PDF: Printable PDF 2010 calendars

With the new year just around the next bend, you might be looking to update your calendars. Thanks to Vertex42.com, users can now download and print a free PDF calendar for 2010. The page lets visitors select from a variety of styles and offers both yearly and monthly calendars.

December 10, 2009
Search Planet PDF
more searching options...







Download PDF Creator

PDF Resources
Platinum Sponsor
Create & Edit PDF - Nitro PDF Software

ARTS PDF

Silver Sponsors

PDF-Tools enfocus

QuickPDF: The Unrivaled PDF Developer Toolkit

Get Nitro PDF Professional
Featured Product

NITRO PDF Professional

Built from the ground up, the perfect desktop PDF product for business and enterprise. Nitro PDF Professional has an uncompromising feature set so you can create, combine, edit, collaborate on and...

Featured Event

No upcoming events

PDF Store Categories