Printing PDF Files (Part 1)

by Jan 16, 2019

To automatically print PDF documents, unfortunately you cannot use Out-Printer. Out-Printer can only send pure text documents to a printer.

However, take a look at this line:

# adjust this path to the PDF document of choice
$Path = "c:\docs\document.pdf"

Start-Process -FilePath $Path -Verb Print

Provided you have software installed that can print PDF document, this code sends the document to the associated program and prints it to the default printer automatically.

Some software (like Acrobat Reader) will stay in memory after that. To kill the program, consider an approach like this:

# adjust this path to the PDF document of choice
$Path = "c:\docs\document.pdf"

# choose a delay (in seconds) for the print out to complete
$PrintDelay = 10

Start-Process -FilePath $Path -Verb Print -PassThru | 
  ForEach-Object{ Start-Sleep $printDelay $_} | 
  Stop-Process

psconf.eu – PowerShell Conference EU 2019 – June 4-7, Hannover Germany – visit www.psconf.eu There aren’t too many trainings around for experienced PowerShell scripters where you really still learn something new. But there’s one place you don’t want to miss: PowerShell Conference EU – with 40 renown international speakers including PowerShell team members and MVPs, plus 350 professional and creative PowerShell scripters. Registration is open at www.psconf.eu, and the full 3-track 4-days agenda becomes available soon. Once a year it’s just a smart move to come together, update know-how, learn about security and mitigations, and bring home fresh ideas and authoritative guidance. We’d sure love to see and hear from you!

Twitter This Tip! ReTweet this Tip!