Using "Verb -print" - How to pass additional parameters?

Alex T-1111 1 Reputation point
2021-10-05T14:45:02.877+00:00

I am new to PS, and am looking to automate printing of files from a directory. I believe I've solved it for a 'real' printer, but in this case I am trying to flatten a .pdf using MS Print to PDF. I haven't been able to find any way to way to pass additional parameters (in this case, the output save location + file name)

Start-Process -file "C:\file.pdf" Verb -Print

As a workaround, I believe this will work to set the default printer (which Print uses) and a custom port (which can be set to a file folder)
Set-Printer -Name "Print to PDF" -Port "C:\OutputPDF\" [Edit: Adding ports can be restricted and does not appear to be a consistent workaround]

This works as long as Adobe is the default .pdf viewer which is an unideal, but acceptable limitation. This will open Adobe with a "Save As" dialog. I am looking to try to automate that final step and pass in a file name to automatically save as. So far I haven't seen an obvious flag that will allow this, and haven't been able to find a way to add input to the print verb or manipulate using the printmanagement PS commands.

This problem seems to be often asked, but no simple solution exists (e.g., not delving deep into multiple .Net classes)
https://learn.microsoft.com/en-us/powershell/module/printmanagement/set-printer?view=windowsserver2019-ps
https://learn.microsoft.com/en-us/answers/questions/503516/printing-using-the-printer-api.html
https://learn.microsoft.com/en-us/answers/questions/224327/print-pdf-to-another-pdf-with-powershell-to-flatte.html

Windows Server Printing
Windows Server Printing
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Printing: Printer centralized deployment and management, scan and fax resources management, and document services
642 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,388 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 45,096 Reputation points
    2021-10-06T01:50:17.307+00:00

    I'm thinking that 3rd-party software is probably the way to go. A product named iText has a decent reputation and works with Java and .Net. I'm pretty sure it's open source, too.

    For lots of examples just search for "powershell itext print pdf" (for example).

    Their site is itextpdf.com

    1 person found this answer helpful.

  2. Rich Matheisen 45,096 Reputation points
    2021-10-05T18:55:56.717+00:00