How can I print a pdf file using powershell on Windows 11?(on an external printer)

I would like to print multiple pdf files using PowerShell.

I have tried multiple solutions available, but they did not work for me.

one solution I tried was the following:

get-childItem "*.pdf" | sort lastWriteTime | foreach-object {start-process $._Name -verb 'print'}

or also:

@("*.pdf") | %{gci $_} | sort Name | foreach-object {while (@(Get-Printer | Get-PrintJob).Count -gt 0) {Start-Sleep -S 3;write-Host . -NoNewline};Write-Host "";Write-Host $_.Name;start-process -FilePath $_.fullname -verb 'print';while (@(Get-Printer | Get-PrintJob).Count -eq 0) {Start-Sleep -S 1;write-Host . -NoNewline}}

The error I get is the following:

Start-Process: This command cannot be run due to the error: An error occurred trying to start process ‘C:Users123files123.pdf’ with working directory ‘C:Users123files’. No application is associated with the specified file for this operation.

I would like to avoid using Adobe Reader or other third-party apps to solve this issue./

To clarify: I would like to print it with an external printer(HP Printer) and not print the pdf again as another pdf file.

I would appreciate any hint.

Thank you!

3

Windows “Print” is the Microsoft legacy print text function from the days before windows. It will work with Text based files and in effect replaces “Copy portable file to port” but portable is a file.PRN not a file.PDF. This MAY work for printers that use “PDF Direct” or mPDF format (not a standard PDF).

We can call the functions to print text (or RTF or minimal DocX) to PDF (or any installed printer driver) very easily so for example at a command send the following line.

echo Hello World!>temp.txt & Write /pt temp.txt "Microsoft Print to PDF" "Microsoft Print to PDF" hello.pdf & timeout 4 & hello.pdf

If your using Acrobat as a PDF handler then the common approach is with (non recommended) kill switch:

$printer = Get-CimInstance -Class Win32_Printer -Filter "Name='Your Printer Name'"
Invoke-CimMethod -InputObject $printer -MethodName SetDefaultPrinter

$Directory = "\Your PDFs SourceFolder"

Get-ChildItem -path $Directory -recurse -include *.pdf | 
ForEach-Object {
    Start-Process -FilePath $_.fullname -Verb Print
    Start-sleep 10
    get-process Acrobat | stop-process -Force
    remove-item $_.FullName -verbose -Force
}

As mentioned the default PDF handler in MS Windows is MS Edge (A Custom Chromium variation). It’s printing command ability is only to produce via headless an image.PNG or vector.PDF from HTML CSS styled files.

You could use it to command line print a “port.PDF” to any output port via VBS or JScript which are both native to the command shell. However that is considered “Old School” and very variable as it depends on timer variables. But is AFAIK the only “native out of box” solution.

Thus native PowerShell has no simple way to auto print a PDF via Edge. But if you pop-up a PDF page the user can quickly print that manually.

That is also a one line command with or without Edge.

Take the example Hello.pdf from above and send command via :

"C:Program FilesMicrosoftEdgeApplicationmsedge.exe" -app="%cd%hello.pdf" and we get a printable pop-up.

All of these commands can also be sent modified or not to console from PowerShell.

Finally there is Kiosk printing where you can first set the default printing device before calling a file in the web kiosk.

Usually for “silent” printing this still needs the user to press print.

"C:Program FilesMicrosoftEdgeApplicationmsedge.exe" --kiosk file://%cd%hello.pdf --edge-kiosk-type=fullscreen --no-first-run  --kiosk-printing

ANSWER

I did Windows “Natively NOOB” send the generated PDF direct to the DEFAULT physical printer (thus could send any other PDF, or with more code change the default).

I strongly suggest you try to avoid this method as often slow or prone to timing failures when attempting faster. However in the spirit of disclosure here is the hardcoded version that will need adapt to variables via args[].

In the following each 1000 is 1 second delay

usage CScript PDF-defaultPrint.vbs

Dim objShell, WshShell
Set objShell = WScript.CreateObject ("WScript.shell")

objShell.run "cmd /c "&Chr(34)&Chr(34)&"C:Program FilesMicrosoftEdgeApplicationmsedge.exe"&chr(34)&" --app="&Chr(34)&"file://C:UsersnameDesktophello.pdf"&Chr(34)&Chr(34)&" "


WScript.Sleep 5000
Set WshShell = WScript.CreateObject ("WScript.shell")
WshShell.AppActivate "hello.pdf"
WScript.Sleep 10000
WshShell.SendKeys "^P"
WScript.Sleep 3000
WshShell.SendKeys "{enter}"
WScript.Sleep 500
Set objShell = Nothing
Set WshShell = Nothing

3

To print multiple PDF files using PowerShell on win11 you can use EDGE to handle the print job.

Ensure Microsoft Edge is Set as the Default PDF Handler:

  1. Go to Settings > Apps > Default apps.
  2. Search for .pdf and ensure Edge is selected as the default application for PDF files.

Use PowerShell to use Edge for Printing:

$pdfFiles = Get-ChildItem -Path "C:Users123files" -Filter "*.pdf" | Sort-Object LastWriteTime

foreach ($file in $pdfFiles) {
    Write-Host "Printing $($file.Name)"
    Start-Process "msedge.exe" -ArgumentList "--headless", "--print-to-pdf-no-header", "--print", "`"$($file.FullName)`"" -NoNewWindow -Wait
    Start-Sleep -Seconds 3
}

Write-Host "Printing."

As for the error that you are getting. That is most likely related to you not having a Default PDF handler set up in the settings of your Win11 installation.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật