Tips & Tricks

Finding user screen resolution with JavaScript

January 12, 2005


PDF's cross-platform nature makes it very portable, but it also means that there is a multitude of different software environments, preference settings and hardware configurations to be found in the potential audience of any widely distributed document. For this reason, it can be really useful to run some JavaScript that checks these things and modifies the behavior of the PDF accordingly.

This is a piece of code that I find particularly useful for consumer or customer documentation -- basically, it checks the user's screen resolution. This information can then be used in a number of ways, but one would be setting a document's initial zoom level based on the user's screen resolution (e.g. If the screen resolution is 800x600 or below, set the document zoom to 65%, but if the screen resolution is above 800x600, set the zoom level to 100%.)

Run this code at document open using document level JavaScript (more on document level JavaScript here.)

// get object representing the primary monitor
var monitors = app.monitors.primary();

// returns an array that represents the monitor's boundaries
var res = monitors[0].rect;

// check if resolution is higher than 800x600
if(res[2] > 800 && res[3] > 600)
	// set document zoom to 100%
	this.zoom = 100;
	// set document zoom to 65%
	this.zoom = 65;
PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Five visions of a PDF Day

In the world of PDFs or as we like to say Planet (of) PDF, a year isn't a real PDF year without an intense few days of industry knowledge sharing.

May 15, 2018
Platinum Sponsor

Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.


Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.