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, www.artspdf.com
*/

// 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");

Planet PDF and ARTS PDF are both divisions of BinaryThing.

Related Products at PDF Store

ARTS PDF Split & Merge Lite

The easiest way to split and merge PDFs! It provides a simpler method of splitting and merging your ... View full product details
Download free demo

Quite Imposing Plus

A plug-in for Adobe Acrobat to perform imposition. Additional functionality is added to that of Quit... View full product details
Download free demo

ARTS PDF Aerialist

Take Acrobat to the next level with advanced splitting and merging; flexible bookmark creation and m... 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