Hello, is it possible to send a file to the default printer to be printed?
I already generate it for PDF, but I wanted to send it to the printer right away.
You could perform a windows API (Shell Execute) to print the file.
The ShellExecute command takes a few parameters, one of which is the filename and the other the action - that action can be âprintâ.
This will cause the OS to print the file with the associated application (basically the same as right clicking in File Explorer and selecting Print).
Hope this helps,
Regards,
Andy
noyantis.com
Thanks a lot for the help.
But Iâm a little confused with the ShellExcute settings.
I donât know which parameter to inform the file and the action.
I have the following signature in the project global:
ShellExecute(UNSIGNED,LONG,*CSTRING,LONG,*CSTRING,SIGNED),UNSIGNED,PASCAL,RAW,NAME(âSHELLEXECUTEAâ)
And the ShellExecute signature of win21.dll is different:
ShellExecuteA(
[in, optional] HWND hwnd,
[in, optional] LPCSTR lpOperation,
[in] LPCSTR lpFile,
[in, optional] LPCSTR lpParameters,
[in, optional] LPCSTR lpDirectory,
[in] INT nShowCmd
ShellExecute example here âŚ
Try setting szOperation to âprintâ
Seems like you want to do something like lpr, but I donât know the best way to accomplish it. Maybe call it directly via cmd? lpr | Microsoft Learn
Itâs true, analyzing the suggestion given above, I found it a little complicated.
Do you know how to call ShellExecute through cmd for printing?
I couldnât find how to make the call.
Sounds like this thread should be renamed : âHow to print a PDFâ.
We use the portable version of Sumatra PDF, it is a single 32bit .exe that I call using RUN() with command line parameters to print.
As I had never done anything like this, I didnât have a starting point.
But I managed with the following solution, using Acrobat via cmd.
Very similar to Julian.
You need to add the path environment variable to the Acrobat DC installation path, the folder where Acrobat.exe is located, to be recognized by cmd.
The printout is sent to the default printer.
Command line options:
Acrobat.exe /s = no splash screen
Acrobat.exe /h = hidden
Acrobat.exe /p = print to default printer
Acrobat.exe /s /h /p MyPdfFile.pdf
To send to a specific printer, follow the command.
Acrobat.exe /t filename.pdf printername drivername portname
printername â The name of your printer.
drivername â Your printer driverâs name. Whatever appears in the Driver Used box when you view your printerâs properties.
portname â The printerâs port. portname cannot contain any â/â characters; if it does, output is routed to the default port for that printer.
How do I change the title of the question?
I have changed it as suggested. (Perhaps you need special privileges to do this?? I had a pencil/edit icon next to the title). *** edit: see Jeffâs answer below
There is at least 1 badge that some folks have that let them rename. For example:
And look at that, I got more likes!
In older versions Acrobat.exe /p used to print without UI, but in later versions direct print was not supported anymore, but i have not checked this in a couple of years.
Some additional options for other people reading this topic:
- If the printer driver understands PostScript (e.g. HP PS driver) you can use GhostScript to convert a PDF to PS and copy it directly to the printer. Like: open file LPT1 write to fle, close file
- Some printers understand PDF. This means you can just write PDF contents to the printer LPT file
n.b. These are heavy printer and printer driver dependent!
I ended up using Windows Printer/dib APIâs because customer kept complaining printing did not work on some printers.