Home

Cardbox

 
Cardbox > Support > Knowledge Base ...

This article uses Cardbox macros. All editions of Cardbox can play macros, but only the Professional Edition can edit or create them.

The macro features mentioned in this article require Build 4266 (or later) of Cardbox. You can check your build with Help > About Cardbox. If it is older than 4266 then you will need to download a newer version.

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 bookmark or page number in the file. Here are two macro functions that will do this for you.

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 OpenAndGoToBookmark function

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

Sub OpenAndGoToBookmark(filename,bookmark) ' Open Adobe Reader and go to a specific bookmark 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).

A sample use of these functions

It is your job to write a macro that extracts the appropriate data from a record and calls OpenAndGoToPage or OpenAndGoToBookmark. 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

© 2008 Cardbox Software Limited
"Cardbox" is a registered trademark of Cardbox Software Limited
 Top of page