Feedback
 
Did this article resolve your question/issue?

   

Your feedback is appreciated.

Please tell us how we can make this article more useful. Please provide us a way to contact you, should we need clarification on the feedback provided or if you need further assistance.

Characters Remaining: 1025

 


Article

How to programmatically print a .PDF file from ABL?

« Go Back

Information

 
Article Number000046047
EnvironmentProduct: OpenEdge
Version: 10.2B, 11.x
OS: Windows
Other: Adobe Acrobat Reader, .NET
Question/Problem Description
How to programmatically print a .PDFfile from ABL?

How to print a .PDF file from programmatically using ABL without having the Adobe Acrobat Reader remain open?
Steps to Reproduce
Clarifying Information
Error Message
Defect/Enhancement Number
Cause
Resolution
The following ABL procedure, which is attached to this KB article for convenience, demonstrates one way of printing a .PDF file using the Adobe Acrobat Reader.  The code uses .NET classes to print a .PDF file and to kill the Adobe Acrobat Reader process after it finishes printing the file:
 
USING System.*.
USING System.Collections.Generic.*.
USING System.Diagnostics.*.
USING System.IO.*.
USING System.Linq.*.
USING System.Text.*.
USING System.Threading.Tasks.*.
 
DEFINE VARIABLE proc AS System.Diagnostics.Process   NO-UNDO.
DEFINE VARIABLE startInfo AS System.Diagnostics.ProcessStartInfo   NO-UNDO.
 
DEFINE VARIABLE sFileName  AS CHARACTER   NO-UNDO.
DEFINE VARIABLE sPrinter  AS CHARACTER   NO-UNDO.
DEFINE VARIABLE sArgs AS CHARACTER   NO-UNDO.
 
ASSIGN
    startInfo = new System.Diagnostics.ProcessStartInfo()
    sFileName = "C:\OpenEdge\WRK\FileName.pdf"
    startInfo:FileName = sFileName
    sPrinter  = "\\ServerName\PrinterName".
 
/* Choose the verb based on whether the file is to be printed to network printer or to the default local printer */
IF INDEX ( sPrinter, "\\") > 0 THEN
    /* prints to a network printer */
    startInfo:Verb = "printto".
ELSE
    /* prints to the local default printer */
    startInfo:Verb = "print".

/* To print on a non-default printer add the following line, with a properly initialized value for sPrinter.
 
startInfo:Arguments=sPrinter.*/
 
This code-change will also be needed for the attached .p file
 
ASSIGN
    startInfo:UseShellExecute = TRUE
    startInfo:WindowStyle = System.Diagnostics.ProcessWindowStyle:HIDDEN
    startInfo:CreateNoWindow = TRUE
    proc = System.Diagnostics.Process:Start(startInfo).
 
/* Wait a maximum of 10 sec for the process to finish */
proc:WaitForExit(10000).
 
IF NOT proc:HasExited THEN DO:
    proc:Kill().
    proc:Dispose().
END.
Workaround
Notes
Last Modified Date4/24/2015 11:54 AM