Consultor Eletrônico



Kbase P25976: 4GL/ABL: How to print PDF documents using Acrobat Reader COM object?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/30/2008
Status: Verified

GOAL:

4GL/ABL: How to print PDF documents using Acrobat Reader COM object?

GOAL:

How to batch print one or more PDF documents in the background and close Acrobat when the printing is done using 4GL/ABL?

GOAL:

Adobe Acrobat Reader 5.0

FACT(s) (Environment):

Windows
Progress 9.x
OpenEdge 10.x

FIX:

DEFINE VARIABLE cDirectoryName AS CHARACTER NO-UNDO.

ASSIGN
cDirectoryName = "c:\AcrobatDocumentsDirectory\".

/* Run the printing procedure */
RUN PrintAllAcrobatDocsInDir(INPUT cDirectoryName).

PROCEDURE PrintAllAcrobatDocsInDir:

/* Define input parameters */
DEFINE INPUT PARAMETER ipcDirectoryName AS CHARACTER.

/* Define object handle variables */
DEFINE VARIABLE hAcroExchAVDocs AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hAcroExchPDDoc AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hAcroExchApp AS COM-HANDLE NO-UNDO.

/* Define local variables */
DEFINE VARIABLE cFileNameList AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE iNumberOfPages AS INTEGER NO-UNDO.
DEFINE VARIABLE iLoopCounter AS INTEGER NO-UNDO.

/* Put all .pdf files of the directory in a string list */
INPUT FROM OS-DIR(ipcDirectoryName).
REPEAT:
IMPORT cFileName.
IF INDEX(cFileName, ".pdf") > 0 THEN
IF NUM-ENTRIES(cFileNameList) = 0 THEN
cFileNameList = cFileNameList + cFileName.
ELSE
cFileNameList = cFileNameList + "," + cFileName.
END.
INPUT CLOSE.

/* Create required Acrobat object instances */
CREATE "AcroExch.App" hAcroExchApp.
CREATE "AcroExch.AVDoc" hAcroExchAVDocs.
CREATE "AcroExch.PDDoc" hAcroExchPDDoc.

/* Print the .pdf documents one at a time */
DO iLoopCounter = 1 TO NUM-ENTRIES(cFileNameList):
cFileName = ENTRY(iLoopCounter, cFileNameList).
hAcroExchAVDocs:Open (cDirectoryName + cFileName, "").
ASSIGN
hAcroExchPDDoc = hAcroExchAVDocs:GetPDDoc
iNumberOfPages = hAcroExchPDDoc:GetNumPages.

/* Internal Adobe page numbering starts at 0 */
hAcroExchAVDocs:PrintPages(0, iNumberOfPages - 1, 2, True, False).
hAcroExchAVDocs:Close(TRUE).
END.
/* Close the acrobat application */
hAcroExchApp:EXIT.

/* Perform cleanup and housekeeping */
RELEASE OBJECT hAcroExchAVDocs.
RELEASE OBJECT hAcroExchPDDoc.
RELEASE OBJECT hAcroExchApp.

END PROCEDURE.