Skip to main content

Print specific files as PDF

Power Automate Desktop has actions in which you specify a file path and print it, but you cannot choose which printer you use.

It may not be possible to print with PDF because it is printed from the default printer.

This time, I will explain how to print a specific file as a PDF.

Solution

Power Automate Desktop has an action that changes the default printer and an action to get the current default printer name.

Use this to keep the default printer name before execution, then change the default printer to a printer for PDF output, and then return the default printer to PDF output.Can be realized.

implemented with copy and paste

We have prepared a sample flow that prints a text file called "document.txt" as a PDF.

Copy the following code and paste it on the edit screen of Power Automate Desktop to add the target action.

Workstation.GetDefaultPrinter PrinterName=> PrinterName
Workstation.SetDefaultPrinter PrinterName: $'''Microsoft Print to PDF'''
Workstation.PrintDocument DocumentPath: $'''C:\\Users\\Public\\Documents\\document.txt'''
WAIT 1
Workstation.SetDefaultPrinter PrinterName: PrinterName

Operate and implement Power Automate Desktop

  1. Enter "Acquire default printer" from "Search Action" and add action.
  2. From "Action Search", enter "Default Printer" and set a printer for PDF output in the "Printer name" ("Adobe PDF" or "Microsoft Print to PDF".)
  3. From "Search Action", enter "Print document" and specify the path you want to print.
  4. Enter "Set default printer" from "Search Action" again, and specify the variables held in 1.

Deposit in the event of an error

If the error ends on the way during this scenario, the default printer may be changed.

We recommend that you put block processing and make sure to return the default printer when an error occurs.