Share via


Printing pdfs to a specific printer

Question

Friday, December 26, 2014 7:35 AM

Hi all

I want to run a script which loops in a folder and print out a pdf if one is coming in that folder. My script looks like this but it is not printing anything. Can someone help me out?

$period = [timespan]::FromSeconds(20)
$lastRunTime = [DateTime]::MinValue 

$searchPath = "\\bu1\Pool\ItemLabel"


#$watcher = New-Object System.IO.FileSystemWatcher
#$watcher.Path = $searchPath
#$watcher.IncludeSubdirectories = $false

while (1)
{
    while ((Get-Date) - $lastRunTime -lt $period) 
    { 
        Start-Sleep -Milliseconds 500
    }
    $lastRunTime = Get-Date
    
    $IncomingPdfs = Get-ChildItem $SearchPath
    ForEach($NewPdf in $IncomingPdfs)
    {
            Start-Process –FilePath ($NewPdf).Fullname -Verb Print | out-printer "BI_PR107"  | %{sleep 10;$_} | kill
            Remove-Item ($NewPdf).FullName
    }

}

All replies (7)

Wednesday, January 7, 2015 11:36 AM ✅Answered | 2 votes

Here is a tested version of the full printer spec.  THis works with all versions of Adobe Reader from version 8 on.  It is direct from teh Adobe SDK.

#Adobe SDK: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/Acrobat_SDK_developer_faq.pdf

$adobe='C:\Program Files (x86)\Adobe\Reader 11.0\Reader\acrord32.exe'
$printername='HP LaserJet Professional P 1102w'
$drivername='HP LaserJet Professional P 1102w'
$portname='192.168.1.100_2'
$pdf='c:\scripts\f1040.pdf'
$arglist='/S /T "{0}" "{1}" "{2}" {3}' -f $pdf, $printername, $drivername, $portname
Start-Process $adobe -ArgumentList $arglist

¯\(ツ)_/¯


Friday, December 26, 2014 12:07 PM

Out-Printer only works with text files.

You cannot redirect the Start-Process command.

¯\(ツ)_/¯


Friday, December 26, 2014 12:24 PM

This can be done with adobe:

$adobe='C:\Program Files (x86)\Adobe\Reader 11.0\Reader\acrord32.exe'
Start-Process $adobe -ArgumentList '/N /T MyDoc.pdf \omega\printername'

¯\(ツ)_/¯


Sunday, December 28, 2014 10:10 AM

Hi, this does not work....it opens PDF but it is not printing


Wednesday, January 7, 2015 10:37 AM

Hi ChrisBern,

If you can print pdf with the default printer, which seems to be easier:

Start-Process –FilePath “c:\docstoprint\doc1.pdf” –Verb Print

Refer to:

Using PowerShell to print pdf files automatically

I also haven't found a good way to print pdf document to network printer.

Best Regards,

Anna Wang

Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]


Tuesday, February 2, 2016 5:46 PM | 1 vote

Just one suggestion for this, get the path to the adobe reader from the registry:

[string]$adobe = $((Get-ItemProperty -LiteralPath 'hklm:\Software\Microsoft\Windows\CurrentVersion\App Paths\AcroRd32.exe').'(Default)')

Tuesday, February 7, 2017 4:18 PM

Where does this script go?
Do I use it in Microsoft Access, or as a bat file,  or where? 

I am trying to automate printing a PDF file to a network printer at a certain
time everyday.  So I was going to use Task Scheduler.

Anything you can provide that would help would be greatly appreciated.

Thanks,

Wade