Sunday, November 20, 2005

JavaScript to bust up a multi-page PDF into single pages

Here's a real handy JavaScript that lots of people could use. One of the neat things about the batch processing function in Acrobat with this script is that you can also have it run the Optimizer. That affords you the ability to do all sorts of cool stuff. Never mind the fact that there are a plethora of other functions you can add as part of a sequence.

Begin JavaScript:

/* extraire */
// regular expression acquire the base name of file
var re = /.*\/|\.pdf$/ig;
var filename = this.path.replace(re,"");
try
{
for ( var i = 0; i < this.numPages; i++ )
this.extractPages
({
nStart: i,
cPath: filename+"_" + (i +1)+".pdf" // (*)
});
}
catch (e)
{
console.println("Batch Aborted: " + e )
}

End JavaScript

You can thank Jimmy Høiby for contributing this to the Enfocus User Group.

Jimmy Høiby
Graphic Designer
Silkeborg Bogtryk
Centraltrykkeriet
Stagehøjvej 27
DK-8600 Silkeborg
Denmark

Matt Beals

1 Comments:

rprond said...

How would you write the JAVA code so that when you split the the PDF it keeps page 1 and 2 together, 3 and 4 together and so on? This code is for splitting it into one page. I need it to split it in groups of two.

1:10 PM  

Post a Comment

Links to this post:

Create a Link

<< Home