Java Script for insert Document

The PDF-XChange Viewer for End Users
+++ FREE +++

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Uhulinchen
User
Posts: 3
Joined: Thu Aug 30, 2012 6:54 am

Java Script for insert Document

Post by Uhulinchen »

Hello there,

I'm quite sure, that I'm not the only one, who got to insert one specific document to some hundered other documents. :D

So I like to ask, if anybody wrote a skript, which add / insert a sepecific document (called bei path\filename or already opend) to a bunch of other documents.

My skills of javascript are very poor, so I need detailled assistance. :oops:

It would be marvellous, if one of you could help me :D

Thanks a lot in advance!

Gaby
Nico - Tracker Supp
User
Posts: 205
Joined: Fri May 18, 2012 8:41 pm

Re: Java Script for insert Document

Post by Nico - Tracker Supp »

Hi Gaby,

Thank you for your post.
Please take a look at the following from the Active X SDK library (https://www.pdf-xchange.com/product ... ctivex-sdk):
  • Active X SDK library examples, i.e.: FullDemo
  • PDFV_AX.pdf manual: 2.2.1.23InsertDocumentPages, 2.3 JavaScript Support sections
  • HTML_JavaScript/PDFXChangeViewer.html
Unfortunately, we don't have a complete JavaScript example yet but from all this information and the JavaScript tutorials from the web (i.e.: http://www.w3schools.com/js/default.asp), you can put something together.
Hope this helps.
Thanks.

Sincerely,
Uhulinchen
User
Posts: 3
Joined: Thu Aug 30, 2012 6:54 am

Re: Java Script for insert Document

Post by Uhulinchen »

Hi Nico,

thank you for your replay. UNfortunatly, it is not enough for me. The Problem behind: I know, I have to tell the system : Take this object, do this and that, but I tried hard with the syntax.

I was a little restless while waiting for help :roll: and finally I found a diffrent forum, which got exact a fitting answer to my request. :P

I'm not sure, if it is against the rule, but hier ist the URL which made my life easier:
http://acrobatusers.com/tutorials/inser ... avascript1

This could be a source for other "problems" like mine.

Thanks a lot for reading my post and spending time on it

All the best
Gaby
Nico - Tracker Supp
User
Posts: 205
Joined: Fri May 18, 2012 8:41 pm

Re: Java Script for insert Document

Post by Nico - Tracker Supp »

Hi Gaby,

Thank you for your post.
It's not against the rule at all, we support the same JavaScript API than Adobe and if you found useful documentation from them that would solve your specific problem, please feel free to share it with us. As you said, somebody else may be looking for that piece of information. From this forum we will do everything we can to help you solve the problems you may come across.
Thanks.

Sincerely,
Uhulinchen
User
Posts: 3
Joined: Thu Aug 30, 2012 6:54 am

Re: Java Script for insert Document

Post by Uhulinchen »

Hi there,

I finally made it!!!!!! :lol: All my dreams came true :mrgreen: :

The script adds a specific pdf (which is specified in the script and must be located in the same directory) to ALL open pdfs
afterwards it saves all the modifiy pdf's and close them.

May be it is not the best way, but it works - that only counts!
I needed to do the three commands in three controll structures, otherwise the script only save and close the active document.

I hope, you may find this helpfull - I love it!

Code: Select all

var len = app.activeDocs.length;
for(var i=len-1;i>=0;i--)

for(var i=len-1;i>=0;i--)
{app.activeDocs[i].insertPages({nPage:this.numPages-1, cPath:"Unbedenklichkeitserklärung.pdf", nStart:0, nEnd:3});}

for(var i=len-1;i>=0;i--)
{app.execMenuItem("Save", app.activeDocs[i]);}

for(var i=len-1;i>=0;i--)
{ app.execMenuItem("Close", app.activeDocs[i]);}
improvement for the code - I divided the three controll structures into three functions, and call them on after the other. So it runs more robust.

Code: Select all

function eins()
{
var len = app.activeDocs.length;
for(var i=len-1;i>=0;i--)
{app.activeDocs[i].insertPages({nPage:this.numPages-1, cPath:"Unbedenklichkeitserklärung.pdf", nStart:0, nEnd:3});}
}

function zwei()
{var len = app.activeDocs.length;
for(var i=len-1;i>=0;i--)
{app.execMenuItem("Save", app.activeDocs[i]);}
}

function drei()
{
var len = app.activeDocs.length;
for(var i=len-1;i>=0;i--)
{ app.execMenuItem("Close", app.activeDocs[i]);}
}

eins()
zwei()
drei()
Have a nice day 8)
Gaby
Last edited by Uhulinchen on Tue Sep 04, 2012 2:15 pm, edited 1 time in total.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19930
Joined: Mon Jan 12, 2009 8:07 am

Re: Java Script for insert Document

Post by Stefan - PDF-XChange »

Hi Gaby,

Glad to hear you got it to work! And I hope it will be useful to other readers of this forum as well!

Cheers,
Stefan