Home

Cardbox

 
Cardbox > Support > Knowledge Base ...

Controlling Adobe Reader

Adobe Reader (downloadable here) is the program that your your computer probably uses to display Acrobat/PDF files. You can make Cardbox open PDF files by using the file: prefix in front of the filename, just as for any other kind of file.

If you do this, Adobe Reader will always show you the start of the PDF file, which may not be convenient if the file is long. You may prefer to go straight to a given location or page number in the file.

Going to a page number

The OpenAndGoToPage function

This function opens a given Acrobat/PDF file and goes to a specified page within it. It requires the PerformAcrobatReaderCommand function to be in the same macro.

Sub OpenAndGoToPage(filename,pageno) ' Open Adobe Reader and go to a specific page. Dim cmd cmd="[DocOpen(""" & filename & """)]" cmd = cmd & "[FileOpen(""" & filename & """)]" cmd = cmd & "[DocGoTo(""" & filename & """," & pageno-1 & ")]" PerformAcrobatReaderCommand filename,cmd End Sub

The PerformAcrobatReaderCommand function

This function is required by both OpenAndGoToPage and OpenAndGoToBookmark.

Sub PerformAcrobatReaderCommand(filename,cmd) On Error Resume Next Application.ExecuteDDECommand "acroview","control",cmd If Err=0 Then Exit Sub ' If we get here, this is because the DDE command failed, probably because Adobe Reader isn't running. On Error Goto 0 ' (turn on normal error handling, so any errors get reported to the user) Launch filename ' (a convenient way to open Adobe Reader is to launch the PDF file) Sleep 2000 ' (wait two seconds to allow Adobe Reader to get started before sending it a command) Application.ExecuteDDECommand "acroview","control",cmd End Sub

This function works by attempting to send the requisite command to Acrobat Reader using the DDE (Dynamic Data Exchange) feature of Windows. This will only work if Acrobat Reader is already running.

If an error occurs, the function tries to start Acrobat Reader. It waits 2 seconds (2,000 milliseconds) to allow time for Acrobat Reader to get going, and then tries to send the command again.

If you sometimes find yourself getting error messages because Acrobat Reader has not started fast enough, try increasing the time limit from 2000 to 5000 (from 2 seconds to 5 seconds).

Using OpenAndGoToPage

It is your job to write a macro that extracts the appropriate data from a record and calls OpenAndGoToPage. Here is an example of opening a document and going to a specific page, in this case page 100:

OpenAndGoToPage "C:\Docs\Acrobat\InterApplication_Communication\iac_api_reference.pdf",100

Going to a bookmark

The first thing to understand about going to bookmarks in Acrobat/PDF files is that you can't. The second thing to understand about it is that you can, but differently. You can't go to bookmarks in Acrobat, but you can go to something called a "named destination".

This is because Acrobat, unlike (say) Microsoft Word, maintains a distinction between the bookmark itself and the destination of the bookmark. What we think of as "going to a bookmark" is actually "looking at the bookmark, discovering where in the document it is pointing, and going to that location". This page (it is on an external site, so it may or may not still exist) explains the distinction.

How to convert bookmarks to named destinations

Because PDF is an open format, there are probably many tools that can perform this sort of manipulation. We have tried one, called AutoBookmark, and it worked. Here is what we did:

  1. Make sure you have Adobe Acrobat installed: not the free Acrobat Reader, but Acrobat itself. We have version 6.0, but later versions should work too.
  2. Download and install the free 30-day trial version of the AutoBookmark plug-in for Adobe Acrobat.
  3. Open the document you want to convert in Adobe Acrobat (not Acrobat Reader).
  4. In Adobe Acrobat, use the command Plug-Ins > Destinations > Create From Bookmarks.
  5. Check the settings you want to use. In our case, we left all the settings at their default values.
  6. Press OK.
  7. Save the modified PDF file.

If you have a great many PDF files, you may want some way of automating this process. We suggest that you contact Evermap, the makers of AutoBookmark. If there is a way of automating AutoBookmark's operation, they will know.

The OpenAndGoToNamedDestination function

This function opens a given Acrobat/PDF file and goes to a named destination within it. It requires the PerformAcrobatReaderCommand function (shown earlier on this page) to be in the same macro.

Sub OpenAndGoToNamedDestination(filename,dname) ' Open Adobe Reader and go to a named destination. Dim cmd cmd="[DocOpen(""" & filename & """)]" cmd = cmd & "[FileOpen(""" & filename & """)]" cmd = cmd & "[DocGoToNameDest(""" & filename & """,""" & dname & """)]" PerformAcrobatReaderCommand filename,cmd End Sub

Using OpenAndGoToNamedDestination

It is your job to write a macro that extracts the appropriate data from a record and calls OpenAndGoToNamedDestination. Here is an example. In this case, it was a named destination called "Opening Remarks", converted by AutoBookmark from a bookmark of the same name.

OpenAndGoToNamedDestination "C:\Reference\Docs\OCP Report.pdf","Opening Remarks"

© 2016 Martin Kochanski
"Cardbox" is a registered trademark.
 Top of page