Hack 9 Browse One PDF in Multiple Windows

figs/moderate.gif figs/hack9.gif

Tear off pages and leave them on your desktop for reference as you continue reading.

Both Adobe Reader and Acrobat confine us to a linear view of documents. Often, for instance, page 17 of a file contains a table I would like to consult as I read page 19, and Acrobat makes this difficult. Here are a couple ways to open one PDF document in many windows, as shown in Figure 1-9. These tricks work with both Acrobat and the free Reader.

Figure 1-9. Using your favorite web browser to open one PDF document in many windows
figs/pdfh_0109.gif


1.10.1 Read PDF with Your Web Browser

One quick solution is to read the PDF from within your web browser. When you open a new browser window (or Mozilla tab), it will duplicate your current PDF view, giving you two views of the same document.

This works in Internet Explorer by default. Mozilla requires a little configuration. In Mozilla, select Edit Preferences . . . Navigator. On the right, find the Display On section and note its adjacent drop-down box. Set Display on New Window and Display on New Tab to Last Page Visited, as shown in Figure 1-10. Click OK. You must restart Mozilla before these changes take effect.

Figure 1-10. Configuring Mozilla to show the current document in newly opened windows and tabs
figs/pdfh_0110.gif


Drag-and-drop a PDF into your browser to open the PDF. Acrobat/Reader should display the PDF inside the browser. Select File New . . . Window (or File New . . . Tab) from the browser menu and you'll have two views into your one PDF.

While you're viewing a PDF file in your browser, the browser hot keys won't work if Acrobat has the input focus. You will need to create new windows or tabs using the browser menu.


If trying to open a PDF inside your browser causes it to open inside of Acrobat/Reader instead, check these settings (Windows only):


Acrobat/Reader 6

Select Edit Preferences . . . Internet. Under Web Browser Options, check the Display PDF in Browser checkbox.


Acrobat/Reader 5

Select Edit Preferences . . . General . . . Options. Under Web Browser Options, check the Display PDF in Browser checkbox.

If you use Acrobat instead of Reader, you will find that many Acrobat-specific features are not available from inside the browser. And, Acrobat won't allow you to save changes to a PDF file, as long as it is also visible in a browser. Close the other, browser-based views to unlock the file before saving.

To get a good blend of both Acrobat features and browser-based PDF viewing, we have a simple Acrobat/Reader JavaScript plug-in that enables you to invoke this "browser view" as needed from Acrobat or Reader. Also look into adding an "Open with Browser" option [Hack #6] to the PDF context menu.

1.10.2 Open a New PDF View from Acrobat or Reader

The following little JavaScript adds a menu item to Acrobat/Reader that opens your current PDF inside a browser window, giving you two views of the same document. To use this hack with Acrobat, you will need to disable Acrobat's web capture functionality by unplugging [Hack #4] its Web2PDF (WebPDF.api) plug-in.

1.10.2.1 Configure Mozilla

If Mozilla is your default browser and you're using Windows, read this section for possible configuration changes.

When Java is disabled, Mozilla often fails to display PDF inside the browser window; it tries to open PDF using an external program, instead. Select Edit Preferences Advanced, check the Enable Java checkbox, and click OK. This is a general problem with Mozilla and is not specific to this hack.

To run this hack with Acrobat 5, you will need to trick Mozilla into keeping its DDE ears open for Acrobat's calls. Mozilla activates DDE when it opens, then deactivates it when it closes. We'll open Mozilla and then alter the Windows http handler. This tricks Mozilla into thinking it is no longer the default browser. Under this illusion, Mozilla won't remove the DDE registry entries it created on startup.

  1. Open Mozilla.

  2. In the Windows File Explorer menu, select Tools Folder Options . . . and click the File Types tab. Select the URL: HyperText Transfer Protocol file type and click the Advanced button (Windows XP and 2000) or the Edit . . . button (Windows 98).

  3. Double-click the Open action to edit its settings.

  4. Add -nostomp to the very end of the Application Used to Perform Action entry, so it looks like this:

    ...\MOZILLA.EXE -url "%1" -nostomp

  5. Click OK, OK, OK.

  6. Close and reopen Mozilla. It will probably complain (erroneously) that it is no longer the default browser. Uncheck the box and click No to keep it from harassing you in the future. If you click Yes, or if you ever change the default browser, your previous changes will be overwritten.

The -nostomp argument is not really a Mozilla parameter. By simply adding this text to the Open action, you trick Mozilla into thinking it is no longer the default browser.

1.10.3 The Code

Copy one of the following scripts into a file called open_new_view.js and put it in your Acrobat or Reader JavaScripts directory. Choose the code block that suits your default browser. [Hack #96] explains where to find the JavaScripts directory on your platform. Restart Acrobat/Reader, and open_new_view.js will add a new item to your View menu.

The script in Example 1-1 is for Mozilla users and opens the PDF to the current page. The script in Example 1-2 is for Internet Explorer users and opens the PDF to the first page.

Example 1-1. open_new_view.moz.js
// open_new_view.moz.js ver. 1.0 (for Mozilla users)

//

app.addMenuItem( {

cName: "-",                 // menu divider

cParent: "View",            // append to the View menu

cExec: "void(0);" } );

//

app.addMenuItem( {

cName: "Open New View &3",  // shortcut will be: ALT-V, 3

cParent: "View",

cExec: "this.getURL( this.URL+ '#page='+ (this.pageNum+1), false );",

cEnable: "event.rc= (event.target != null);" } );

Example 1-2. open_new_view.ie.js
// open_new_view.ie.js ver 1.0 (for Internet Explorer users)

//

app.addMenuItem( {

cName: "-",                 // menu divider

cParent: "View",            // append to the View menu

cExec: "void(0);" } );

//

app.addMenuItem( {

cName: "Open New View &3",  // shortcut will be: ALT-V, 3

cParent: "View",

cExec: "this.getURL( this.URL, false );",

cEnable: "event.rc= (event.target != null);" } );

You can download these JavaScripts from http://www.pdfhacks.com/open_new_view/.

1.10.4 Running the Hack

After you restart Acrobat, open a PDF document. From the View menu, select Open New View. Your default browser should open and display the PDF, giving you two views of the same PDF.