Use Acrobat JavaScript to Change a PDF’s Initial View
Question details
Use PDF metadata to select an initial page layout and zoom with Acrobat JavaScript.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF already contains metadata that should determine its initial page view when opened.
- Observed behavior
- The desired result is a document-level script that reads the metadata and applies the appropriate view settings.
Open the PDF in Adobe Acrobat and check File > Properties > Description to identify the metadata field and value you want to use. Confirm that JavaScript is enabled in Acrobat’s preferences and that you can edit and save the PDF.
Add a metadata-based document-level script in Acrobat
Use this approach when the initial layout must change according to a PDF metadata value.
The example reads the Subject metadata field, sets zoom to 100%, and chooses SinglePage when the value is exactly single-page; otherwise, it chooses OneColumn. Replace Subject and the comparison value with the field and value used by your PDF.
The addScript method takes a script name and one script string. Use === for comparison rather than =, which assigns a value.
In Acrobat, open File > Properties > Description and check the field and exact value that should control the layout.
Open Acrobat’s JavaScript console and enter: this.addScript("Initial view settings", 'var initialview = this.info.Subject;\nthis.zoom = 100;\nthis.layout = (initialview === "single-page") ? "SinglePage" : "OneColumn";');
Execute the statement in the console, then use File > Save to save the document-level script in the PDF.
Close and reopen the saved PDF in Acrobat. Check the zoom and layout, then test a PDF with a different metadata value if both branches are needed.

Set a fixed initial view in PDF properties
Use Acrobat’s Initial View settings when the layout does not need to depend on metadata.
Read and manage PDFs alongside Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. Open compatible files in one suite for an easy transition; use Acrobat when you need to create or test Acrobat-specific document JavaScript.

Frequently Asked Questions
Why does my if statement always choose the same layout?
Check whether you used = instead of a comparison operator. For example, initialview === "single-page" compares the value, while initialview = "single-page" assigns it.
How many script strings can I pass to addScript?
Pass a script name and one script string to this.addScript. Combine the zoom and layout statements in that single string.
Where can I check the PDF metadata used by the script?
In Acrobat, open File > Properties > Description. The example uses this.info.Subject, so check the Subject field or change the script to use the appropriate metadata field.
Why doesn’t the initial view work in my browser?
Browser PDF viewers may ignore document JavaScript and initial-view settings. Close the browser view and open the saved PDF in Acrobat to test the script.
Can I automate this for multiple PDFs?
For a batch workflow in Acrobat Pro, investigate a customized Preflight fixup and an Action or Droplet. Test the workflow on representative PDFs before applying it to the full set.




