0

I have used the below .NET ABL code to print the pdf using the default printer option. Now I want to set those Printer and Page settings. I know they are in System.Drawing.Printing setting, but anyone knows how to integrate this with the ProcessStartInfo to print it with those parameter settings.

USING System.*.
USING System.Collections.Generic.*.
USING System.Diagnostics.*.
USING System.IO.*.
USING System.Linq.*.
USING System.Text.*.
USING System.Threading.Tasks.*.
USING System.Drawing.*.

DEFINE VARIABLE proc AS System.Diagnostics.Process   NO-UNDO.
DEFINE VARIABLE startInfo AS System.Diagnostics.ProcessStartInfo   NO-UNDO.
DEFINE VARIABLE printerSettings AS System.Drawing.Printing.PrinterSettings   NO-UNDO.
DEFINE VARIABLE pageSettings AS System.Drawing.Printing.PageSettings   NO-UNDO.


DEFINE VARIABLE sFileName  AS CHARACTER   NO-UNDO.
DEFINE VARIABLE sPrinter  AS CHARACTER   NO-UNDO.
DEFINE VARIABLE sArgs AS CHARACTER   NO-UNDO.

/* HOW To Handle Printer and Page Settings here? 
ASSIGN
    printerSettings = NEW System.Drawing.Printing.PrinterSettings()
    printerSettings:PrinterName = "Microsoft Print to PDF (redirected 4)"
    printerSettings:Copies = 01.
    
ASSIGN
    pageSettings = new System.Drawing.Printing.PageSettings(printerSettings). 
*/

ASSIGN
    startInfo = new System.Diagnostics.ProcessStartInfo()
    sFileName = "C:\temp\file.pdf"
    startInfo:FileName = sFileName    
    sPrinter  = "Microsoft Print to PDF (redirected 4)"
    startInfo:Verb = "print"
    startInfo:Arguments=sPrinter.

ASSIGN    
    startInfo:WindowStyle = System.Diagnostics.ProcessWindowStyle:HIDDEN
    startInfo:CreateNoWindow = TRUE
    proc = System.Diagnostics.Process:Start(startInfo).
proc:WaitForExit(15000).
IF NOT proc:HasExited THEN DO:
    proc:Kill().
    proc:Dispose().
END.

Any help will be highly appreciable. Regards

  • Looks like you're trying to combine the solution from this answer https://stackoverflow.com/a/6106155/1428261 and this here https://stackoverflow.com/a/41751184/1428261 - I doubt that is possible. Have you tried downloading the Google PDFium library from https://github.com/pvginkel/PdfiumViewer/releases or the Nuget link? – Mike Fechner Apr 27 '21 at 18:32
  • Hello Mike, Apologies for late reply. I was using the 3rd party pdf reader like pdfp.exe, PDFtoPrinter.exe but they are not have enough parameters that I am looking to pass to print my PDF. I am using API to download a PDF, and need to print that PDF using the on screen parameters of printer name, pages, copies, paper size, etc. You are right, I am trying the above code from https://stackoverflow.com/a/41751184/1428261 which is using PDFiumViewer libraries to print the pdf, integrating it an open edge application is one of the challenge I am facing. Will keep you posted. Thanks for help. – MasterPanda May 14 '21 at 05:40
  • i use this command line exe for printing pdfs https://stackoverflow.com/a/47994723/13055261 – FloW Jun 02 '21 at 12:43
  • Thanks @FloW . I have tried this before but the problem is it has limited control over the printing for example I need to have the orientation, paper size, and collate options which this doesn't provide. There is a setting.dat option from PDF-Xchange but I want the above options on fly, can't edit dat file through progress. – MasterPanda Jun 02 '21 at 23:54

0 Answers0