Skip to main content
Participant
September 28, 2020
Question

How can I programmatically set Document Properties > Initial View?

  • September 28, 2020
  • 3 replies
  • 2530 views

Question: How can I programmatically set Initial View settings while running a VBA macro?

Background: I'm working on an Excel tool that includes manipulating PDFs. I'm not an experienced programmer, but I've been able to figure out how to do the following via VBA:

  • Create bookmarks
  • Set document properties, e.g., Title, Author, Subject, etc.

I also found code that allows me to call JavaScript code with VBA, which I'm using to run a script (by Thom Parker) to clean up bookmarks. For reference, here's the VBA I'm using to call Javascript:

 

If avdoc.Open(File, "") Then
'//write JS-Code on a variable
Ex = " // Put JavaScript Code here...

'//Execute JS-Code
AForm.Fields.ExecuteThisJavaScript Ex
MsgBox ("Done")
End If

 

Additional Details:

  • It looks like I'm not able to do this with JavaScript, but is this correct? If I can set standard doc properties metadata, it seems to me that I ought to be able to set the Initial View settings??
  • I read that I'm not able to run an Action programmatically -- is that, in fact, the case? I've got an Action to do what I need.
  • I found lots of forum posts asking about manipulating PDFs that included responses saying, "Look at the SDK," but I've spent a ton of time looking through it but wasn't able to find anything.
  • I've learned that there is a ViewerPreferences dictionary in PDFs, but I can't find anything on how to manipulate its properties. If I can manipulate the metadata in the Info Dictionary, it would seem to me that I could similarly manipulate the ViewerPreferences dictionary??

 

So, I'm stumped but hopeful that there is some way in which I can set Initial Settings.

 

Thank you!

This topic has been closed for replies.

3 replies

Bernd Alheit
Community Expert
Community Expert
September 28, 2020

You can set the initial view with a plugin written in C/C++.

Participant
June 6, 2023

Can you help with this plugin?  Do you have any pointers on what APIs this plugin might use?

Thom Parker
Community Expert
Community Expert
June 6, 2023
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Karl Heinz  Kremer
Community Expert
Community Expert
September 28, 2020

Joel has already given you the answer to your question. Here is some additional information: Every time you say to yourself "I ought to be able...", you need to review the documentation. In this case, because you are trying to use the JavaScript API via the JSObject, you need to take a look at Acrobat's JavaScript API documentation, which you can find here:

 

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJS_API_AcroJSPreface%2FJS_API_AcroJSPreface.htm

 

You may have to expand the table of contents on the left side to see the structure of the document. In this case, because you wnt to do something that is specific to a document, you would have to review the properties and methods of the "Doc" object. 

 

Just because you think somethign should be possible, does not necessarily mean that it actually is 🙂 I've fallen into that trap a few times myself...

Eric5EBBAuthor
Participant
September 29, 2020

Thanks, all, for taking the time to respond.

Karl, regarding your closing sentence: yes, you are right. 🙂 Meanwhile, I will take a look at the Doc object, just to learn a bit more about it.

Joel Geraci
Community Expert
Community Expert
September 28, 2020

You can't set Initial View using JavaScript