Help Needed: Merging PDFs with Correct Order

Hello RPA Community,

I need help with a process I’m developing and unfortunately, I’m out of ideas.

Initial situation:

I have several files (PDFs) in my Downloads folder, and now I want to merge some of them (those with identical names for example with “Worksheet” at the beginning) into one file. I’ve used the “Join PDF Files” activity for this. However, I’ve noticed that the order of the documents is not correct, meaning page 10 comes before page 1 because they are sorted alphabetically instead of numerically. Unfortunately, I can’t seem to get the correct order to be preserved.

Example of how these PDFs look that I would like to merge:

Worksheet - UiPath Mon 25.11.2024 - 1.pdf
Worksheet - UiPath Mon 25.11.2024 - 2.pdf
Worksheet - UiPath Mon 25.11.2024 - 3.pdf
.
.
Worksheet - UiPath Mon 25.11.2024 - 10.pdf
and so on…

Perhaps someone here has an idea on how to maintain the correct order

Edit: This is process will run daily so the Day and Date will change everyday from the pdf files.

@henry.hartmann,

You should have a fixed format to sort the files with names and then merge.

@henry.hartmann

please try giving this in join pdf files activity array avriable

directory.GetFiles("Folder Path","Worksheet*").OrderBy(function(x) Cint(System.Text.RegularExpressions.Regex.Match(x,"\d+(?=\.pdf)").Value)).ToArray

this would start the files with the order of number at the end

cheers

Hello Anil,
thanks for the input, I tried the code but when I started debugging it an Error appeared:
"Assign: Conversion from string "“to type ‘Integer’ is not valid.”

The variable typ is currently set to: ArrayOf String I tried changing the typ to ArrayOf Ing32 and normal String but then a error appears on the code before debugging it. :sweat:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.