Printing PDF to paper from command line and get print job ID

I need to make a command line program that can be passed a path and it will silently print the PDF without any prompts and will return the job ID for the print so that another process can then use it to check the status of the print from the spooler (this part code is not necessary).

If there is some sort of 3rd party library that would be great but nothing that requires a license since (aka free).

If you could help in any way that would be appreciated. A lot of the windows spooler api's are very low level and I have no idea how to make that work for pdf.
I think you can do this from the command line tool without making a program. It can list jobs etc and print a file for you, at least. A smart batch file may be all that is needed here?

I looked for a way to do this via Windows Powershell for a while a few months ago, but there does not seem to be an easy way.

I assume OP is using windows, otherwise a command like
lpr -P your_favorite_printer your_document.pdf
should work.
Last edited on
I don't have a printer at the moment, what did not work, do you recall?
I can put in a to-file printer and fool with it, see if it is doable... but not tonight.
Last edited on
I sidestepped my original problem by scraping the data I needed into a plain-text file. I was able to send plain text to the printer but not a PDF document.

For some unknown reason the system forgets the network printers periodically. Similarly it also changes the default printer whenever for no obvious reason. I can't do anything about the root cause.

I was able to reconfigure the printer(s) programmatically by calling into printui.dll from the command line.

To actually print plain text I used something like
Start-Process -FilePath document.txt -verb Print -Wait
Which didn't work for PDF files.
Last edited on
Hmm. There is a shell option to print non-text with right click, but I am not sure how to tap that from a console.
Topic archived. No new replies allowed.