These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Insert/Merge Pages using Javascript

unexist
Registered: Aug 27 2007
Posts: 4

[i]Hello ppl,

I have a big problem. I have several PDFs on a Server where one PDF is the "Master PDF". What i want to do now is to open the "master PDF" and in this "Master PDF" are some buttons. If I click one of these buttons it should be able to insert the pages of another PDF on the Server.

Example:

I have the master.pdf
I open it, and there is from Indesign a button (which also works in PDF) which runs the Java Script Code when the left mouse button is released. And this button says: Insert the pages of the slave.pdf to the now opened Document.

I thought this is an easy 1 row code, but...
I have managed this so far but I think I haven't done the correct JavaScript Code. Here is my Code:

function MergeMultipleFiles()
{
var doc = app.newDoc();
vFiles = new Array("/C/TestPDF/First.pdf","/C/TestPDF/Second.pdf","/C/TestPDF/Third.pdf");
for ( var i=0; i < vFiles.length; i++)
{
doc.insertPages ({nPage: doc.numPages-2,cPath: vFiles,nStart: 0});
}
}[/i]

The problem is, this code has no effect when I try to click the button. Is the reason why it doesn't work the opened document? Sry but i never programmed Java before and this is my first try, but now I'm stuck. I hope anyone could help me.

I also tried the command

this.insertPages({cPath: "file2.pdf"})

but nothing happens

[color=#FF0000]EDIT:[/color]
[color=#FF0000]I managed to delete some pages out of my document with the command this.deletePages & Params. But now, when I try to insert some pages from another pdf the console says: 'NotAllowedError: Security settings prevent access to this property or method.'
Doc.insertPages:5:Field System 1:Mouse Up

Anyone has an idea?[/color]

With best regards,
unexist

EdGioja
Registered: Sep 26 2007
Posts: 25
insertPages is a priveleged command where deletePages is not.

Take a look at JavaScript for Acrobat API Reference for a discussion on this, and the Developing Acrobat Applications using Javascript about Folder level scripts.