Skip to content

Print a specific file as a PDF

Power Automate Desktop has a built-in action that prints a file by its path, but you can’t choose which printer to use.

Because the file is printed on the default printer, you may not be able to print it as a PDF.

This article explains how to print a specific file as a PDF.

Power Automate Desktop provides an action that changes the default printer and an action that gets the name of the current default printer.

With these, you can output a PDF by saving the name of the default printer in a variable before printing, changing the default printer to a PDF printer, and then restoring the original default printer after printing.

As a sample, here’s a scenario that prints a text file named “document.txt”, saved in the Public Documents folder, as a PDF.

Copy the following code and paste it into the Power Automate Desktop flow designer to add the actions.

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
  1. In “Search actions”, type “Get default printer” and add the action. The name of the current default printer is saved in the variable PrinterName.
  2. In “Search actions”, type “Set default printer” and set a PDF printer in “Printer name” (for example, “Microsoft Print to PDF”, which comes with Windows, or “Adobe PDF” if you have Adobe Acrobat installed).
  3. In “Search actions”, type “Print document” and specify the path of the file you want to print.
  4. Again, in “Search actions”, type “Set default printer” and set “Printer name” to the variable %PrinterName% that you saved in step 1.

If the scenario ends with an error partway through, the default printer may be left changed. We recommend adding an “On block error” block so that the default printer is always restored, even when an error occurs.