Win2PDF.com has offered a free online HTML to PDF converter for some time, but it has limitations. It only works with public web pages, not private pages on an intranet or local HTML files. It also can’t be automated.
From a Command Prompt window, just issue the command:
win2pdfd.exe html2pdf "sourcehtml" "destpdf"
The “sourcehtml” can be a specific local HTML file or a web URL. If the file name or path contains spaces, make sure to include double quotes (“”) around the complete source file name or URL. The URL can be specified as “https://www.example.com” or “www.example.com”.
Over the next series of posts we’ll show some examples of how this can be done in a real-world context using Win2PDF.
First, let’s start off by using an example where we want to automatically rename a bunch of PDF invoices that are stored in a folder. And then suppose we not only want to rename the PDF files, but we want the new file names to be based on some content within the original files, such as the number following the word “INVOICE”.
Notice how the Win2PDF command line getcontentsearch feature is used. It allows us to search for the word “INVOICE” in the PDF file, and then return the following content (in this case, the INVOICE number) to the standard output. After trimming any extraneous spaces from this invoice number, the PDF file is renamed to be that invoice number.
You can use the graphical user interface to make your own flow, or you can copy the following into a new Power Automate Desktop flow if you want to use this as a starting point for your project:
# 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
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
This example shows one way to use Win2PDF’s automation features to create a solution unique to your workflow. It also uses features that were added in the latest Win2PDF 10.0.100 update, so make sure you are using the latest Win2PDF 10 Update when trying any of the Power Automate Desktop features.
Can you think of any similar cases that you might use? If so, drop us a line. We’ll have more examples coming soon.