Kbase P134249: How to batch print multiple MS Word documents in the background using 4GL
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  22/09/2008 |
|
Status: Unverified
GOAL:
How to batch print multiple MS Word documents in the background using 4GL
FACT(s) (Environment):
Windows
Progress 9.x
OpenEdge 10.x
FIX:
- In order to perform multiple print jobs of Word documents, please use the source code below:
DEFINE TEMP-TABLE t-pj NO-UNDO
FIELD pj-nu AS INT LABEL "Label 1" /* replace "Label 1" with the text of your choice */
FIELD pj-lib AS CHAR FORMAT "x(100)" LABEL "Label 2" /* replace "Label 2" with the text of your choice */
FIELD pj-nom AS CHAR FORMAT "x(100)" LABEL "Label 3" /* replace "Label 3" with the text of your choice */
INDEX cle pj-nu.
CREATE t-pj.
ASSIGN t-pj.pj-nu = 1
t-pj.pj-lib = ""
t-pj.pj-nom = "drive:\directory\file.doc".
CREATE t-pj.
ASSIGN t-pj.pj-nu = 2
t-pj.pj-lib = ""
t-pj.pj-nom = "drive:\directory\file.doc".
CREATE t-pj.
ASSIGN t-pj.pj-nu = 3
t-pj.pj-lib = ""
t-pj.pj-nom = "drive:\directory\file.doc".
/* You can create as many instances of t-pj as you need */
DEFINE VARIABLE ctr-doc AS INTEGER NO-UNDO.
ctr-doc = 0.
FOR EACH t-pj NO-LOCK:
ctr-doc = ctr-doc + 1.
END.
DEF VAR chWord AS COM-HANDLE NO-UNDO.
DEF VAR chDoc AS COM-HANDLE NO-UNDO.
CREATE "Word.Application" chWord NO-ERROR.
ASSIGN chWord:VISIBLE = FALSE.
FOR EACH t-pj NO-LOCK BREAK BY t-pj.pj-nu:
chDoc = chWord:Documents:OPEN ( t-pj.pj-nom , , YES ).
chDoc:Printout ( /* , , , , , , , 1 */ ) .
chDoc:CLOSE(0).
RELEASE OBJECT chDoc.
IF ctr-doc > 1 THEN
RUN CheckPrinting1.
END.
PROCEDURE CheckPrinting1:
PAUSE 1 NO-MESSAGE.
IF chWord:BackgroundPrintingStatus > 0 THEN
RUN CheckPrinting2.
END PROCEDURE.
PROCEDURE CheckPrinting2:
PAUSE 1 NO-MESSAGE.
IF chWord:BackgroundPrintingStatus > 0 THEN
RUN CheckPrinting1.
END PROCEDURE.
chWord:QUIT(0).
- Because sending a Word document to print as a background process is an asynchronous request, multiple print jobs will fail after the first print if the previous request was not processed and completed first. Hence the need for the procedures CheckPrinting1 and CheckPrinting2. CheckPrinting1 will check the background printing status and call CheckPrinting2 if a document is being printed. CheckPrinting2 will make the same check and call CheckPrinting1 if a document is being printed. This loop will continue until BackgroundPrintingStatus = 0, when the loop will be escaped.