Progress KB - How to programmatically print a .PDF file from ABL?




Feedback
Did this article resolve your question/issue?

   

Article

How to programmatically print a .PDF file from ABL?

« Go Back

Information

 
TitleHow to programmatically print a .PDF file from ABL?
URL Name000046047
Article Number000177249
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
Attachment 
Disclaimer The origins of the information on this site may be internal or external to Progress Software Corporation (“Progress”). Progress Software Corporation makes all reasonable efforts to verify this information. However, the information provided is for your information only. Progress Software Corporation makes no explicit or implied claims to the validity of this information.

Any sample code provided on this site is not supported under any Progress support program or service. The sample code is provided on an "AS IS" basis. Progress makes no warranties, express or implied, and disclaims all implied warranties including, without limitation, the implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample code is borne by the user. In no event shall Progress, its employees, or anyone else involved in the creation, production, or delivery of the code be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample code, even if Progress has been advised of the possibility of such damages.