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

Open to Page - page number based on filename via Javascript

Laszlo Prekop
Registered: Jul 14 2011
Posts: 2
Answered

Hi,
 
I wonder if it's possible to set File / Properties / Initial View / Open to page field automatically based on the pdf-s name (ie TOC-german_page0003.pdf should show the third page when opened in Acrobat Reader or Acrobat). We have literally thousands of this kind of documents, right now we have to set this poperty manually and this is a very time consuming and error-prone task.
 
Maybe thru PDFMarks? (Detailed in this article:
http://acrobatusers.com/blogs/lkassuba/setting-initial-view-property-your-pdfs )
 
ie:
 
[ /PageMode /UseOutlines /Page 3 /View [/XYZ null null null] /DOCVIEW pdfmark
where /Page 3 should be a variable instead of a constant integer.
  
Or maybe with a document level js? Is it possible to attach doc level js to a pdf from a javascript?

 
Thanks in advance,
Laszlo

My Product Information:
Acrobat Pro 5.x or older, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
To answer your question, yes, it's possible, but only using a script that identifies that number in the file's name when it's opened and then switches to that page.
It's even possible to apply this script to multiple files, but only if you have Acrobat Pro with the capability to execute batch sequences. You wrote that you have a very old version of Acrobat Pro, so I'm not sure if you'll be able to do it without upgrading.

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

Laszlo Prekop
Registered: Jul 14 2011
Posts: 2
Thanks a million, I successfully completed my script – the Open to Page part looks something like this:

//Add the page switcher code to pdf
this.addScript({cName: "Open To Page Number", cScript: "var openToPageNr = parseInt(this.path.slice(this.path.length-8,this.path.length-4),10)-1;\n this.pageNum = openToPageNr; \n"});

Which basically adds a script to a pdf (this.addScript),
- which gets the last 4 characters of the filename (this.path.slice),
- converts it to a number (parseInt),
- and then jumps to this page number (this.pageNum).

(later the script saves the files under different filenames in a loop, to make the script attachment permanent).

Tomorrow we will test this in the work environment, which is at the moment based on Acrobat 5, but it will be upgraded to CS5.5 soon, so compatibility won't be an issue.

Thanks again,
Best,
Laszlo
cmwch2011
Registered: Jul 26 2011
Posts: 2
Hi everybody,
I have a similar task to perform as described by Laszlo.
We produce a pdf - file containing text in 3 different languages. In order to present the reader the text in his language respectively, we copy the file twice and set the initial starting page number, the initial zoomfactor (fit window - width and the initial title (document title instead of file name) manually.
We've automated the process a little bit by using the actions functionality, but would like to have a fully automated process, i.e. setting these entries automatically (preferably vb.net)
I could not imagine this to be so extremely difficult, but did not find any solution by studying almost every docs / tutorials available.

Therefore, I would highly appreciate your kind advise how to store the information of these 3 entries in a pdf file automatically.

Many thanks for your help in advance
Kind regards

C. W. (Zurich, Switzerland)

try67
Expert
Registered: Oct 30 2008
Posts: 2398
I can imagine this being done with a batch action that saves three copies of each file, each one with a different doc-level script that sets the right page and zoom factor. I'm assuming that the length of all document is the same, ie that if you have a 9-page document, then the first one begins at page 1, the second at page 4 and the last at page 7. If that's not the case, then it becomes more complicated...

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