Printing PDF documents from command line

New Topic
This topic has been archived, and won't accept reply postings.
 LastBoyScout 17 Jan 2020

In brief, I have a piece of software that generates PDF documents, which users can then print.

I want to be able to automatically print the documents on a specific printer as part of a batch process and have found the following command line and parameters:

AcroRd32.exe /s /h /o /t MyFile.pdf "MyPrinter"

This works, but has the downside that it loads up the GUI as part of the process and I can't find a way of suppressing this - googling indicates it's not possible, but perhaps someone on here might know more?

I'm trying to avoid having to use a 3rd party product, for a number of reasons.

Thanks in advance.

 remus Global Crag Moderator 17 Jan 2020
In reply to LastBoyScout:

Reading the docs it seems like you've got pretty limited options if you want to stick with acrobat. One (messy) approach could be to print the file and then kill the AcroRd32 process with something like 

taskkill /F /IM AcroRd32.exe

You might want to add a little sleep in there to give acrobat a bit of time to print the doc, as Im not sure how well it'll behave if you start the process then kill it straight away.

If you can use some third party software, this looks good http://www.columbia.edu/~em36/pdftoprinter.html

pasbury 17 Jan 2020
In reply to LastBoyScout:

I've tried developing software that interacts with acrobat and it's awfully painful; in my case it was a reader of formatted documents. Acrobat behaves like an unruly teen-ager spawning offspring all over the place. It doesn't have what I would call an API. Why use pdfs?

Post edited at 18:23
 Philip 17 Jan 2020
In reply to LastBoyScout:

More than 10 years ago I had printers than accepted PDF directly. And before that PS. Can't you just pipe your PDF directly to the printer.

 morpcat 17 Jan 2020
In reply to LastBoyScout:

I don't have anywhere to test right now but you should be able to do this with lpr: https://docs.microsoft.com/en-us/windows-server/administration/windows-comm...

(Or if it's an option use a Linux OS, which should have the LP command)

OP LastBoyScout 17 Jan 2020
In reply to remus:

Thanks, but taskkill probably not the way forward, as user might have it open for other documents. It would also slow the process down to unacceptable levels to do this, especially with added sleep time.

We already have a 3rd party utility in place to convert the files from RTF into PDF and that will also do the printing I want, but it seems to do something to the PDF on the way to the printer and introduces a formatting issue.

OP LastBoyScout 17 Jan 2020
In reply to Philip:

> More than 10 years ago I had printers than accepted PDF directly. And before that PS. Can't you just pipe your PDF directly to the printer.

It's a good idea, but the "printer" here is actually not a printer at all, but a driver for generating bulk mail shots - it does some clever scanning of the documents to lift addresses to put on envelopes, which seems to fail if I send it the documents via our 3rd party utility, as mentioned in last post.

OP LastBoyScout 17 Jan 2020
In reply to morpcat:

Thanks - I'll have a look into that...

 Mike-W-99 18 Jan 2020
In reply to LastBoyScout:

I’m not in the office so can’t double check but you might be able to use powershell to launch it and keep it hidden. The documentation certainly implies it can do this.

 wercat 18 Jan 2020
In reply to Philip:

I seem to remember you could do something like that in CP/M! not pdfs though

 Lemony 18 Jan 2020
In reply to LastBoyScout:

I wonder if you could use a headless browser to do it? Heavyweight but might work.

In reply to Philip:

> More than 10 years ago I had printers than accepted PDF directly. And before that PS

I recall using a simple copy command, copying the document (ps or pdf) to a network printer name.

 SenzuBean 18 Jan 2020
In reply to LastBoyScout:

I'm not too sure on what the problem with the GUI is. Is it that it's intrusive? Or that it slows things down?

If you use powershell to invoke the process, you can specify that it should be a hidden process - that may be useful for you ( Start-Process -WindowStyle hidden -FilePath notepad.exe if it works..)
You could even wrap the invocation so that for a batch process, your PS script creates a new hidden reader (/n - Launch a new instance of Reader even if one is already open), which it re-uses for the rest of the batch jobs, and then that hidden process is killed at the end of the processing (using powershell you can easily keep the processId of the process you created, and then kill that only specifically). That would be the way I'd be attempting it (until/if any blocker problems occurred.. )

In terms of speed - well, I'm not sure there's much you can do. There are some PDF libraries out there that will let you print (they vary wildly in quality), and it may be faster to use those directly, than to use adobe's exe.

 Mike-W-99 21 Jan 2020
In reply to LastBoyScout:

Did you get anywhere with this?


New Topic
This topic has been archived, and won't accept reply postings.
Loading Notifications...