4 Replies Latest reply on Dec 11, 2009 7:41 AM by Bernd Alheit

    Batch Scripting to Automate PDF Combination/Bookmark Creation

    jesmiles

      I have a number of PDFs where some represent emails and some represent attachments to those emails. Currently they are all saved as separate PDF files; what I would like to end up with is a single PDF per email, where each attachment has been inserted after the last email page and a bookmark has been created called the name of the attachment, which is dynamic and not related to the file name.

       

      I have a list of which PDF attachments would need to be added to which PDF emails, including the name of what each bookmark would be. I have used this list to auto-create a javascript that I thought would do the trick. Here is a sample of what I created:

       

      //***************************************************************

      /* Combine Files */

       

      //Open first PDF email and create a bookmark to mark the email

       

      varMyDoc = app.openDoc("/Z/Projects/IMG_0001/S-00001.pdf")
      varMyDoc.bookmarkRoot.createChild("057-063_Fw _59.msg", "varMyDoc.pageNum=0", 0)

       

      varPage = varMyDoc.numPages

       

      //Insert pages from the attachment PDF after the last page of the email and create a bookmark to mark the attachment

       

      varMyDoc.insertPages ({nPage: this.numPages-1,cPath: "/Z/Projects/MG_0001/S-00002.pdf"})
      varMyDoc.bookmarkRoot.createChild("20060329092508655.pdf", "varMyDoc.pageNum=" + varPage, varPage)

       

      //Save the new combined PDF to a new location and close it

       

      varMyDoc.saveAs("/Z/Projects/IMG_0001/S-00001.pdf");
      varMyDoc.closeDoc(true);

       

      //***************************************************************

       

      My plan was to create a batch sequence to run this and copy/paste the entire script into the script window. However, I now realize that my script is really not a batch sequence. I can run the first execution (above) as a batch sequence if I have that one file open in Acrobat, but as soon as I try to add in opening the next file, the script stops.

       

      I don't need to run the exact same commands for every file in a directory, which is what the batch sequence wants to do; I want to simply run the script and have it open, insert pages, make changes, and save the files according to the way the commands are laid out.

       

      I also tried to save the script with a .js extension and put in the JavaScripts directory, but I get an error in the debugger saying that my variable bookmarkRoot has no properties... the script seems to run differently this way than it does through a batch sequence and my syntax or usage is no longer correct.

       

      Is there a way to use Acrobat this way? I would try automating this from VBA or something, but it looks from the developer's guide like bookmarks can't be created using that method. I'm basically trying to automate Acrobat from an external script the way you can automate Excel or Word using vbscript; you just make object representing an instance of that application and then you can use methods and properties just like you would if you were scripting inside that application natively. Can an instance of Acrobat be pulled up from just running an external .js?