How to print to pdf from powershell

One morning, while finalizing a network monitor report, I wondered: Can I export a file to PDF without installing anything? No GhostScript, no PDF libraries, no third-party tools. Just PowerShell and what Windows already offers.

The answer was yes. And its name is: Microsoft Print to PDF.

Step One: Understanding the “PrintTo” Mechanism

PowerShell doesn’t natively “print” to PDF. But it can launch an application and send it a PrintTo command. If “Microsoft Print to PDF” is installed — and it is on all modern Windows systems — we can use it as a silent converter.

Example 1: Printing a .txt File to PDF

Set-Content -Path "$env:TEMP\\report.txt" -Value "This is a test report generated from PowerShell."
$source = "$env:TEMP\\report.txt"
Start-Process -FilePath $source -Verb PrintTo -ArgumentList '"Microsoft Print to PDF"'

Result: A save dialog appears. Not fully automatic, but zero dependencies. That was the first AHA moment.

Example 2: Printing a .csv File via Excel

$csv = "$env:TEMP\\report.csv" | Set-Content -Path $csv

Start-Process -FilePath $csv -Verb PrintTo -ArgumentList '"Microsoft Print to PDF"'

Prerequisite: Excel must be the default CSV editor.

Excel launches, initiates printing, and prompts for PDF location. Again — no extra tools.

Here is what happens:
Set-Content: Creates a CSV file with basic data.
Start-Process -FilePath $csv: Tells Windows to open the file.
-Verb PrintTo: Instructs Windows to launch the associated app (Excel) and send the file to the specified printer.
-ArgumentList '"Microsoft Print to PDF"': Specifies the target printer.

What Actually Happens

If Excel is installed and set as the default .csv handler, it will launch silently and initiate the print-to-PDF flow.
If another app (e.g., Notepad or LibreOffice) is the default, that app will be used instead.

Example 3: Printing a .docx File via Word


$docxPath = "C:\Users\Public\Documents\report.docx" Start-Process -FilePath $docxPath -Verb PrintTo -ArgumentList '"Microsoft Print to PDF"'

This one requires Word to be installed, but it works beautifully. The file is created, opened, and sent to the PDF printer.

But… Where’s the Output?

Here’s the limitation: PrintTo doesn’t let you specify the output path. Windows opens a save dialog, and the user must manually confirm the location.

For me, that’s acceptable — everything else is automated. But if you need a fully silent conversion, you’ll need additional tools (e.g., PDFCreator CLI, SumatraPDF a /print-to, or COM interop with Word’s ExportAsFixedFormat).

Conclusion

This method isn’t perfect, but it’s clean—no external dependencies. No installs. Just PowerShell, Windows, and a printer that’s already there.