WORD -> PDF using ActivePDF

Jenie888

Member
I am using a product called active PDF to generate PDF files.

When generating Report Building files to a PDF it works fine, however when generating a word document to a pdf I have experianced some problems.

I have been able to recreate the error EVERY time.

The first time I run the procedure it generates the word -> PDF perfectly.
The second time, I do not get any errors, it generates a blank PDF page.
It appears that it can't write to the PDF form after the first time, but I don't see what I am doing wrong.

The PDF service is still up and running becuase during this time I am able to create PDF's from report Builder reports, HOWEVER if I stop the PDF service and Start it back up again I am able to generate another WORD doc into a PDF, but again dies the second time I run the procedure.

Does anyone have any ideas as to what I might be doing wrong?

Here is a copy of my code - I also attached the complete files.

Thanks,
Jenifer

DEFINE OUTPUT PARAMETER attach-name AS CHARACTER NO-UNDO.

DEF VAR TheLordsPrinter AS CHAR NO-UNDO.
DEF VAR TheLordsPort AS CHAR NO-UNDO.
DEF VAR OutDir AS CHAR NO-UNDO.
DEFINE VARIABLE chWord AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chDoc AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE v-Map AS COM-HANDLE NO-UNDO.
DEF VAR i AS INTEGER NO-UNDO.
OutDir = SESSION:TEMP-DIRECTORY.
DOS SILENT ERASE VALUE(SESSION:TEMP-DIRECTORY + REPLACE("JenTest", " ", "") + " " +
REPLACE(sTRING(today), "/", "-") + " " +
TRIM(USERID ) + ".pdf") NO-ERROR.
CREATE "APServer.Object" v-Map.
IF OutDir = "" THEN
OutDir = v-Map:outputdirectory.
v-Map:OutPutDirectory = OutDir.
CREATE "Word.Basic" chWord.
NO-RETURN-VALUE chWord:AppHide("Microsoft Word").
v-Map:NewDocumentName = REPLACE("JenTest", " ", "") + " " +
REPLACE(sTRING(today), "/", "-") + " " +
TRIM(USERID ) + ".pdf".
i = v-Map:StartPrinting().
IF i <> 0 THEN
DO:
MESSAGE "Error on Start-Printing()"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RELEASE OBJECT chWord .
RELEASE OBJECT v-Map .
LEAVE.
END.

TheLordsPrinter = v-Map:NewPrinterName.
TheLordsPort = v-Map:NewPortName.
ASSIGN i = chWord:ToolsOptionsPrint (0 /* draft */,
0 /* reverse */,
0 /* update fields */,
0 /* summary */,
0 /* show codes */,
0 /* annotations */,
0 /* show hidden */,
0 /* env feeder installed */,
1 /* window control */,
1 /* dflt true type*/,
0 /* update links */,
0 /* background */).
NO-RETURN-VALUE chWord:FileOpen("n:\JenieTest2.doc").
NO-RETURN-VALUE chWord:AppShow("Microsoft Word").
NO-RETURN-VALUE chWord:FilePrintSetup(TheLordsPrinter + " on " + TheLordsPort).
NO-RETURN-VALUE chWord:FilePrint.
NO-RETURN-VALUE chWord:FileClose(2).
NO-RETURN-VALUE chWord:AppClose("Microsoft Word").

IF i = 0 THEN
DO:
MESSAGE "Error on WAIT(60)"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RELEASE OBJECT chWord .
RELEASE OBJECT v-Map .
END.
/* // v-Map:WaitForPDFGen. */
v-Map:StopPrinting.
i = v-Map:WAIT(60).


ASSIGN attach-name = v-Map:outputdirectory + REPLACE("JenTest", " ", "") + " " +
REPLACE(sTRING(today), "/", "-") + " " +
TRIM(USERID) + ".pdf".


RELEASE OBJECT chWord .
RELEASE OBJECT v-map .
 

Attachments

Back
Top