Tips & Tricks

Collating PDFs using JavaScript

December 08, 2004

Advertisement
Advertisement
 

Planet PDF's Introduction to Acrobat JavaScript Learning Center defines JavaScript as a scripting language that provides "...the ability to automate and maintain...PDF documents from within Acrobat." In this and other JavaScript tips, I will explain just how to use Acrobat JavaScript to do just that.

Although the end result is convenient and space-efficient, there are many potential issues when considering the conversion of paper documents into electronic archives. For instance, when scanning a large volume of paper pages into PDF with an Automatic Document Feeding (ADF) scanner, it's common to end up with two separate PDF files: one with all of the odd-numbered pages, and another with the even-numbered ones. Depending on the page count of the document or documents in question, it can be a laborious and time-consuming task to collate the two files manually using Adobe Acrobat.

Here's helpful script for collating two PDFs:

Note: Although I originally wrote this to be executed via a custom tool button using ARTS PDF Aerialist, you can also execute it from Acrobat Professional's JavaScript debugger.

/*
  Title: Collate Document
  Purpose: User is prompted to select document to insert/collate.
  Author: Sean Stewart, ARTS PDF, http://www.debenu.com/arts-pdf/
*/

// create an array to use as the rect parameter in the browse for field

var arRect = new Array();
arRect[0] = 0;
arRect[1] = 0;
arRect[2] = 0;
arRect[3] = 0;

// create a non-visible form field to use as a browse for field

var f = this.addField("txtFilename", "text", this.numPages - 1, arRect);

f.delay = true;
f.fileSelect = true;
f.delay = false;

// user prompted to select file to collate the open document with

app.alert("Select the PDF file to merge with")

// open the browse for dialog

f.browseForFileToSubmit();
var evenDocPath = f.value;

var q = this.numPages;

// insert pages from selected document into open document

for (var i = 0;i < q; i++) {
    var j = i*2;
    this.insertPages(j, evenDocPath, i);
} 

// remove unused field

this.removeField("txtFilename");

(ARTS PDF and Planet PDF have been since acquired by Debenu)

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.