Merge PDF Documents and Rename based on Content using Power Automate Desktop

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
thank you greetings and salutations in today's video I demonstrate not only how to merge PDF documents in a systematic way but how to read those documents and extract key values then use those values to rename the newly created merge PDF documents all using power automate desktop version let's begin so we have a bunch of PDF documents that we need to add a cover page to the cover page will be the same for all and our mission at hand is to add the couple page to each of the PDF documents in an automated way I have some sample invoices here these are just some sample invoices but each one has a different invoice number located here our cover page is in a different folder and it's just a single page with the words cover page on it we will cycle through each of these files and add the cover page to each invoice and then rename the invoice based on the invoice number then we will place that renamed file in a different folder here okay so we have a new flow set up here with no actions yet well the first thing we want to do is gather up our Target PDF documents we do that with the get files in folder action [Music] next the folder we insert the location of our PDF documents not including our cover page make sure that is in a different directory we can set our file filter to be PDF documents only with the star.pdf because I also have an Excel file in that directory that I want to ignore our variable produce will be called files save that I'm going to move some PDF documents out of our directory so that I can work with just one for now so only our sample after PDF document will be picked up now we want to cycle through our PDF documents so let's use a for each Loop our value to iterate will be the output from our CAD files called files now let's extract the text from our PDF there's an action called extract text from PDF our variable will be the current item in the loop on our pages to extract can be all as our sample invoices are only one page anyway the output will be extracted PDF text save that so if we run this on our one file let's see what our expected tax looks like let's run this and our values will show up on the right side here if we open it up we see our text our Target text is the first line so a way we can extract the first line is to split our text on new lines and assign each line to a list we do that with the split text action our text to splits will be our extracted PDF text a standard delimiter type and the delimiter will be a new line this will produce the variable text list let's run this to see the output okay so each line can now be referenced by an index number and the line that we want is line number zero now we are going to assign a variable to this line in our list foreign I will change the variable name to line and our value will be text list and to Target the first line we add a zero in the brackets before the last percentage like so so if we run this a line variable will contain our Target line now if we wanted to rename this file this entire line we would be done with the step but let's make it a bit harder and just Target the actual invoice number zero zero two zero so if the number after the dash well we can do that by performing another split on this line variable so add another split text our text slits will be our line variable our delimiter type will be custom this time and our custom delimiter will be the dash let's output this variable to a variable called number save that our number variable would now contain just the invoice number on the second line great we have our Target name will be called now we will copy our files into the temp directory that also has our cover page PDF using our copy files action our files to copy will be the current item our destination folder will be the location of our cover page PDF and if the file already exists let's overwrite it you will see why we are copying the PDF into the directory that contains the cover page with our next action our next action will be to perform the merge on the PDF files we have to select all the PDF files we wish to merge so let's call a get files and folder action then reference that in our PDF files so cancel this for now and add a get files in folder action we can add our PDF filter as well and let's put the output it as our m files now we call our merge and reference our m-files so our PDF files will be m-files our merge PDF path is the location where we want the merge PDFs to be saved even though it says merge PDF path it actually wants you to specify the name as well so let's call it merged PDF yeah and if the file exists add a sequential suffix our output will be merged PDF now after we copy the file and perform the merge let's delete the copy file from our directory our file to delete will be our copy file variable save that now let's run that and see what kind of output we get okay we have a merge PDF file but if we open it it's not in the correct order a cover page is page 2 in the document we want the cover page to be the first page let's fix that when we get the files in our temp folder let's sorted first by name open our get files in folder action expand advance and turn on sort by name also turn on descending that way when we get our files it will be in somewhat of a consistent order based on the name of our cover page let's run that again okay now our cover page is the first page and our invoices are second great okay now let's work on the renaming aspect I'll save you the trial and error of getting this to work but before we call the rename file action we need to trim the white space from a variable so we need to call trim text action text to trim will be our number variable in our second line which is referenced like so and we store this value in trimmed text variable what this does is remove white spaces more specifically new line characters that gets added and causes problems with our rename action okay now that we have that we can call our rename function our file to rename will be our merge PDF output the rename scheme will be set a new name the new file name will be our trimmed text variable and we want to keep the file extension on and if the file exists let's do nothing we can turn off the option to produce a variable name for this so let's go over what we're doing here we get all PDF files in a given location with flow one then we Loop over these files and extract all the text from the PDF we then split the text from the PDF on new lines so each line is in the PDF is assigned a location on in a list because our PDFs are uniformed the line we want to extract will always be on the first line then we split the line on a dash to get only the invoice number and not the wording then we copy that file in the directory with our couple page we get those files in the directory and perform a merge on those files we copy that file to our Target directory delete the original PDF from our temp directory we then rename our PDF based on the invoice number we extracted [Music] okay let's run this on all our files and see what we get [Music] foreign [Music] [Music] [Music] [Music] [Music] and that's it we have just completed a merge on PDF documents by adding a cover page and successfully renaming each sample invoice based on the invoice number hopefully you found this video useful and if so please consider subscribing if you have any tasks you would like to see automated using power automate desktop version please let me know in the comment section thanks for watching this video has been brought to you by AIP Solutions
Info
Channel: AIP IT Solutions
Views: 2,308
Rating: undefined out of 5
Keywords:
Id: zWkW7AN-JNg
Channel Id: undefined
Length: 16min 5sec (965 seconds)
Published: Fri Mar 10 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.