Copy link to clipboard
Copied
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:
printDoc.insertPages({
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?
As the documentation states: "If a page range is not specified, the method gets all pages in the source document."
So simply don't specify nStart and nEnd. More info: https://acrobatusers.com/tutorials/inserting-pages-pdf-acrobat-javascript1
Copy link to clipboard
Copied
As the documentation states: "If a page range is not specified, the method gets all pages in the source document."
So simply don't specify nStart and nEnd. More info: https://acrobatusers.com/tutorials/inserting-pages-pdf-acrobat-javascript1
Copy link to clipboard
Copied
Wow. I can't believe I completely didn't absorb that line in the documentation when I read it. Or didn't read it at all. In any case, I feel like a fool now. Sorry to have bothered you with something so trivial, George_Johnson​. But thank you immensely for helping, and so quickly, too!
Although, a thought experiment comes to me that would invalidate that possibility. What would someone do if they needed to copy over all pages *except* the first page? My guess is that you'd have to do that "Pre-open document A and count the pages" trick. Your thoughts?
Copy link to clipboard
Copied
You can copy all of the pages and then delete (doc.deletePages) the one(s) you don't want.
Copy link to clipboard
Copied
Clever solution! That would be easy enough to do and saves time from having to open and close a file. Thanks for indulging my curiosity!