1

I am trying to print a PDF using powershell and AcroRd32.exe and now run into a problem I can't solve by myself. If I am executing the code and Acrobat Reader opens but no print job is generated. I can even see my pdf in the latest use files.

This is my code:

$file = "C:\temp\file.pdf"
$adobe = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
$driver = "HP Universal Printing PCL 6"
$port = "10.200.1.63:3910"

$printer = "\\pserver\printer07"
$arglist = "/s /t $($file) $($printer) $($driver) $($port)"
Start-Process $adobe -argumentlist $arglist -wait

I tried the following:

  1. Checking if the file I am trying to print exists and is accessible [YES]
  2. Tried to print with dialog: argument "-p $($filename) [WORKS]
  3. Checked if the printer is accessible by the computer [YES]
  4. Double checked printername, driver and port... [YES]

Even without driver and port I am not able to print a file through this code.

Does anyone have useful tips or suggestions to solve this problem?

Mofi
  • 46,139
  • 17
  • 80
  • 143
pregunta
  • 138
  • 1
  • 11
  • 1
    If you ar eon Windows, why are you calling Adobesirectly at all? When Adobe is installed, all .pdf associations will point to it, so Windows knows to start Adobe by default. No reason to call it explicitly. Just open the file and call print. It will use the default printer on the host. Now, if you are saying, you want to print to pdf, then set the pdf printer as the default printer and that is what will be used, then set it back to the original printer. [Get-ChildItem -Path 'D:\temp' -Filter 'testPrintPdf.pdf' | ForEach-Object {Start-Process -FilePath $PSItem.FullName -Verb 'Print' -Wait}] – postanote Sep 28 '20 at 07:33
  • Im printing from a client using powershell and windows task sheduler to print an online generated and downloaded pdf file on several network printers. – pregunta Sep 28 '20 at 07:35
  • 1
    I recommend to open [Acrobat SDK Developer FAQ](https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/Acrobat_SDK_developer_faq.pdf) (PDF file) and read the page 24 which is about usage of Adobe Acrobat or Adobe Reader from command line and which options it supports. The printer name must be the name of one of the printers installed already on the Windows machine. I doubt that `\\pserver\printer07` is the correct name of the installed printer. See also [Printing PDFs from Windows Command Line](https://stackoverflow.com/questions/19124808/). – Mofi Sep 28 '20 at 10:21
  • @Mofi well, the solution was to use the local name of the printer. I added it to the client but with a more readable name. I'm still wonderin why it's not working with `\\pserver\printer07` – pregunta Sep 28 '20 at 12:09

1 Answers1

1

This might be the cause of your problem or not, but there are spaces in $driver, so you definitely need to add quotes in the command line (I did it for all variables, just in case):

$arglist = "/s /t `"$file`" `"$printer`" `"$driver`" `"$port`""
marsze
  • 15,079
  • 5
  • 45
  • 61
  • Thanks for the hint but unfortunately it still doesn't work. – pregunta Sep 28 '20 at 07:35
  • @peoples Are you sure you have the right syntax for the command line? Have you tried putting it all in plain text in a batch file and running that? If that doesn't work, it's not a powershell problem but an issue with your command arguments. – marsze Sep 28 '20 at 07:47
  • I tested it but I got the same result as described above. Adobe Reader opens, I can see the file in latest use files "just now" and no print job is generated. – pregunta Sep 28 '20 at 07:58