4 Replies Latest reply on Sep 21, 2016 11:02 AM by Sturm359

    Insert all pages to the end of a document

    Sturm359 Level 1

      I'm attempting to do something that *should* be easy: Add all of the pages from document A to the end of document B. There is even a built-in command for copying pages from one document to another: Doc.insertPages. My problem lies in the limits of that method.


      See, whenever this script will be run, I do not know how many pages are in document A beforehand. Doc.insertPages lets me specify the first and last page that I want to copy over, but it only expects a number. Also, sadly, using -1 to specify the last one doesn't work for page index numbers the way it works for an Array's index number. So here's what I have so far:


          nPage: printDoc.numPages - 1,
          cPath: labelFile,
          nStart: 0,
          nEnd: -1


      Here, printDoc is my document B, and labelFile is my document A. I can easily tell the method to insert the pages after that last existing page in document B by calling its numPages property and subtracting 1. After all, the document is already open and Acrobat can count the pages in it. Not so for document A; the Doc.insertPages method doesn't open up document A--it only wants a String path to it. Thus, I cannot tell ahead of time how many pages are in it.


      I suppose I *could* just have the script open up document A temporarily, just long enough to store its number of pages into a variable, which will then be used in the Doc.insertPages method, but I was hoping for something a bit more tidy than that. Thoughts/ideas?