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

Bug in replacePages (or in documentation)

try67
Expert
Registered: Oct 30 2008
Posts: 2398

I believe I found a bug in the replacePages() method of the Document object.
According to the documentation:

Quote:

If nStart and nEnd are not specified, gets all pages in the source document.

 
But when I run this method without specifying any of these parameters, just the first page from the source file is being replaced, not all of them.
 
Can anyone else confirm this? I tested it in Acrobat Pro 8, 9 and 10 and all behaved the same.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

My Product Information:
Acrobat Pro 10.1, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Seems like a documentation bug, which as you know there are several. It kind of makes sense that it behaves this way.
maxwyss
Registered: Jul 25 2006
Posts: 255
It appears to be a discrepancy between the application and the documentation; I checked the documentation back to Acrobat 5, and it always says that all pages are replaced.

I tried it in Acrobat 5 (where the function has been introduced), and it replaces the first page only.

Therefore, I would consider it to be a documentation bug. Who reports it?


try67
Expert
Registered: Oct 30 2008
Posts: 2398
Thanks for looking into it, guys.
In my (humble) opinion, though, it's more likely an implementation bug. If you specify only the nStart parameter, only that page is being used and if you specify only the nEnd parameter the range from 0 to that page is used, so I would expect that if neither is specified the entire document will be used. So the behavior when not specifying anything is like specifying nStart:0 (and omitting nEnd), which doesn't make much sense to me.

As it stands now, unless you explicitly open the replacement file, record the number of pages in it, and then close it and use that number as your nEnd, you can't use the entire file for the replacement.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

maxwyss
Registered: Jul 25 2006
Posts: 255
There seems to be more ambiguity in the replacePages() method. In my understanding, it is the JavaScript equivalent to the Document --> Replace Pages… dialog. There, you specify which range of pages in the original document will be replaced with pages from the inserting document. The number of pages will be the same. But then, in order to achieve the same behavior as with the dialog, the page number from which to start in the inserting document is missing; at the moment, it is always beginning with the first page.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
I don't quite follow, Max... In the lower part of the Replace Pages dialog you can specify from which page number to begin in the replacement file, and it starts from that page. At least in versions 8 and 10, where I tested it...

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

maxwyss
Registered: Jul 25 2006
Posts: 255
Yes, you have it in the dialog, but there is no argument in the JavaScript function for that.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
nStart and nEnd, no?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

maxwyss
Registered: Jul 25 2006
Posts: 255
nStart and nEnd relates to the document to be modified, but there is no argument stating thhe beginning page in the document from which the replacement pages are taken.

Simple scenario: Your working document is DocuA. Let it be a quote for a machine. That machine uses a motor from your standard motor catalog (let's call it MoCat). You now change the motor with another motor from your catalog.

In DocuA, the motor data sheet is from page 12 to page 14.

The original motor's data sheet is MoCat pages 46 to 48.

The new motor's data sheet is in MoCat pages 381 to 383.


Now, do that programmatically… nStart is 11, nEnd is 13, but where do you say that the replacement pages start at page 45 or 381??

You could do a very kludgy workaround: extract the replacement pages from MoCat using extractPages() to a temporary file, and then run replacePages() using that temporary file.

Max.

try67
Expert
Registered: Oct 30 2008
Posts: 2398
You got it wrong. nStart and nEnd specify the pages in the document that is used for the replacement, not in the document whose pages are getting replaced. nPage represents the first page in the document to be modified that should be replaced.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

maxwyss
Registered: Jul 25 2006
Posts: 255
Hmmm

I have to agree that I was confused. You are right, of course, and that then sufficiently defines the replacement.