0

I am trying to print a pdf from my application using this osprint.p option, I am able to use the printer option of saving pdf but the pdf is not in a readable format This is how it looks. any idea what I am doing wrong. Also, is there any option to set a default printer through this along with other options like the number of copies, collate, etc, without triggering MSW Print Setup dialog box I want to programmatically send these options?. With the below 4th parameters I am able to do the orientation and the paper size but don't how to set others.

/* RUN ShellExecuteA (0,"print":u,cUserFile,"default_Printer","",1,OUTPUT tInt). */ 
/* Using ShellExecute I won't be able to set orientation or any other options */                   
RUN adecomm/_osPrint.p (INPUT wWin, 
                        INPUT cUserFile,
                        INPUT 3,
                        INPUT 1 + IF fc-orient-portrait = 1 THEN 0 ELSE 2 + i-papersize + 160 + 512,
                        INPUT 0,
                        INPUT 0,
                        OUTPUT vResult).
IF vResult THEN DO:            
  OS-DELETE VALUE(cUserFile).
END.

For reference, I am using this article from Chris: https://www.progresstalk.com/threads/printing-on-ladscape-mode.48/ along with this one: https://knowledgebase.progress.com/articles/Knowledge/18776

Thanks Ahead.

1 Answers1

1

_osprint.p cannot be used to print PDF files. As the file header (https://github.com/consultingwerk/ADE-Sourcecode/blob/master/src/adecomm/_osprint.p) says it's purpose is to send a text-file to a printer.

The easiest to print a PDF file is to use the ShellExecuteA API, e.g.:

PROCEDURE ShellExecuteA EXTERNAL "shell32":U:
    DEFINE INPUT PARAMETER HWND         AS LONG .
    DEFINE INPUT PARAMETER lpOperation  AS CHARACTER .
    DEFINE INPUT PARAMETER lpFile       AS CHARACTER .
    DEFINE INPUT PARAMETER lpParameters AS CHARACTER .
    DEFINE INPUT PARAMETER lpDirectory  AS CHARACTER .
    DEFINE INPUT PARAMETER nShowCmd     AS LONG .
    DEFINE RETURN PARAMETER hInstance   AS LONG .
END PROCEDURE .

DEFINE VARIABLE hInstance AS INTEGER NO-UNDO.

RUN ShellExecuteA (0,
                   "print",
                   "c:\temp\oe-122-pdfs\start.pdf",
                   "",
                   "",
                   3,
                   OUTPUT hInstance) .

See https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea for options.

If you have some experience with OpenEdge GUI for .NET it should be straight forward to translate the answer that mentions the Google Pdfium library to ABL:

How can I send a file document to the printer and have it print?

Mike Fechner
  • 6,627
  • 15
  • 17
  • Thanks a lot for this. I might have missed that it doesn't print pdfs. ShellExecute is very limited with its parameters setting but I like that .NET option and it looks straightforward. I will try to implement that and will post about it. Thanks again. Regards. – MasterPanda Apr 27 '21 at 04:31
  • 1
    Hello Mike, Here is the latest development as per your suggestions: https://stackoverflow.com/questions/67287801/want-to-add-page-and-printer-settings-in-the-below-code-for-printing-the-pdf – MasterPanda Apr 27 '21 at 17:20