Please enable JavaScript to view this site.

Navigation: How To Articles > Automating Win2PDF with Microsoft Power Automate Desktop > Win2PDF Power Automate Desktop Example Flows

How To Rename PDFs based on File Contents Using Power Automate Desktop

Scroll Prev Top Next More

The following Microsoft Power Automate Desktop flow shows how to rename a folder of PDFs in place using the Win2PDF Desktop command line getcontentsearch command. The flow searches the PDF files for a field named "INVOICE :", and then renames the PDF based on the text immediately following the "INVOICE :" field. You can configure the search field by changing the "SearchText" variable.

 

This flow requires Win2PDF 10.0.100 or above.

 

power-automate-desktop-pdf-content-rename-flow

 

To use this "flow", copy the following into a new Power Automate Desktop flow:

 

# This flow searches the contents of PDF files in the selected folder for SearchText, and renames the PDF files based on the text immediately following SearchText. Change the SearchText variable to the desired search field. Note : the SearchText field is case sensitive.

SET SearchText TO $'''INVOICE :'''

Display.SelectFolder Description: $'''Select Folder to Rename''' IsTopMost: False SelectedFolder=> SelectedFolder ButtonPressed=> ButtonPressed3

Folder.GetFiles Folder: SelectedFolder FileFilter: $'''*.pdf''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files

LOOP FOREACH CurrentItem IN Files

  # Search for %SearchText% field and return following text in CommandOutput using the following Win2PDF command line:

  # C:\Windows\System32\spool\drivers\x64\3\win2pdfd.exe getcontentsearch "%CurrentItem%" "" "%SearchText%"

  System.RunDOSCommand DOSCommandOrApplication: $'''C:\\Windows\\System32\\spool\\drivers\\x64\\3\\win2pdfd.exe getcontentsearch \"%CurrentItem%\" \"\" \"%SearchText%\"''' StandardOutput=> CommandOutput StandardError=> CommandErrorOutput ExitCode=> CommandExitCode

  IF CommandExitCode = 0 THEN

    Text.Trim Text: CommandOutput TrimOption: Text.TrimOption.Both TrimmedText=> TrimmedText

    File.Rename Files: CurrentItem NewName: $'''%SelectedFolder%\\%TrimmedText%''' KeepExtension: True IfFileExists: File.IfExists.Overwrite RenamedFiles=> RenamedFiles

  ELSE

    Display.ShowMessageWithTimeout Title: $'''Win2PDF Renamer''' Message: $'''Could not find \"INVOICE :\" field for file %CurrentItem%''' Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False Timeout: 10 ButtonPressed=> ButtonPressed4

  END

END