Power Automate - تبدیل یک pdf به چند صفحه به صورت خودکار

ساخت وبلاگ

I have a PDF with several documents in it that could be PDFs that I want to split with power automate desktop that is straightforward let me show you how in this PDF we have six different documents you can find these file samples by clicking the link in the description below or choose your own we can choose a prompt dialog that will prompt the user for the path to this document we could also choose a variable in here we will have a display select file dialog that will prompt the user that comes up on the screen and as the user so here I'll say please provide the path of the PDF you want to split then I want an initial folder that is where our prompt will start in so click this folder here usually you might want to start in documents but since I have a desktop with a project folder on I'll start here it doesn't make really a lot of sense to look for more files than PDF so I can say look for each every file that is DSD risk but only those ones that will end with DOT PDF I can also say do I want this prompt to go on top yes please allow multiple selection I'll create the full solution that can take as many documents as you want with the PDFs in but for now we will have it once check if file exists doesn't really matter it will exist when the user picks it automatically but we can actually enable it if the user for somehow provide an illegal path then we want to say the variables produced that is selected file I want to rather have it in selected PDF file so always rename your variables so you can see what's going on and your colleague can see what's going on it looks like this so I run it and this will prompt the user so I can for example pick the first PDF that I got here and the flow will stop because we have no more actions here we have the path to the PDF here and that's what I said you could have a set variable or this path could come from different places in your flow this solution is just with display select file dialog but feel free to change it now we want to split it our strategy is to create a loop that takes the first page out the second page out so forth in this PDF we have six pages so when it tries with page seven it will fails and we will take advantage of that so let's create a solution I'll find a set variable this one will keep track of what page we are at so the name we will call it something meaningful again like page count and then I'll give it the value 1 because the first page is always page one this isn't a value from document this is just the value that we give it it corresponds to this page number up here you can see that the first page is always page one even though we have no page number in it so a variable that will always exist in the document there'll always be a page one I'll also use if I want to create some sort of a detailed error handling then I want a set variable with a status in so I'll just say status and I'll give it the status okay for now everything is okay a desk that could change then I can click save now I want to make the loop that will Loop all the pages that might be here in the selected PDF file I'll find a loop condition and I'll drag this one in here so the loop condition is a loop that runs over and over as long as a condition is true that means that if something didn't don't change this condition then this Loop will run forever it's not really ideal so we also we always want something to change that changes it so the first operand I'll run on my status here if that is equal to okay then I can run the loop like this now I can extract the files so first I will go up here then I'll find and extract PDF file PDF file pages to a new PDF file here I can say I only want to take a certain page number out and extract that to a PDF and so the PDF file that is the file that we got selected we selected up here selected PDF file so click this x double click the selected PDF file the page selection well we have a value for that that is the page count that is one in the first instance we need to add one to this page count each time the loop runs otherwise it will stay at page one we will fix that when we are finished here where do I want to extract it to I think it makes a lot of sense to extract it to whatever directory that this file appears in so I click this X and then I'll say selected PDF file I will expand it and then I will find the directory double click it now I want to make a little prefix on into the PDF file names so I will say backslash then I'll say split and then I'll use the name that we have originally from up here so I'll take this one here and I'll find the selected PDF file and then I'll the name yes if the file exists and it will do because we extract it over and over then we want to give it a little number we could also use the page count for that but for now the add sequential suffix is working fine if you have a password on your PDF you can go into advanced and specify that the variable produced that will be extracted PDF that is fine for now so then I can click save we said that we want to split each one of the pages right now we only have page one so we need to add one to the page count variable so here I will find a set variable and drag it in here I'll pick the page count like this click this little X here say page count and then inside the percentage sign in here I'll say add one to it so now we are adding 100 over and over and this could go on forever if the um the PDF file had an unlimited amount of pages it will not so this one when it comes to page seven in our case this will break and the robot will stop working so we need to counter for that so what I want to do here is that I will actually say well an out of bound arrow that is not real an error that will change my status so it's not an error that will affect should affect my workflow in any other way that you should just exit the loop so down here in the end I will have a label I also have a subflow but I'll pick a label that goes into here I will give this label out of about the name out of bounds like this now I can say if this produces an arrow then you should just stop here we could write a message to the status and then as you just go to the label so just completely exit the loop and go down here so I can move in here and then I can pick the on Arrow and I can say all errors well I don't want to look at them I only want to look at the outbound Arrow so expand the advanced go to the page out of bounds and click that one here I will not draw an arrow that will stop my robot if I don't count for that but I will continue flow run and what do I want to do here well I want to go to label and that will be out of bounds that is the one I created down here the robot will stop we know that we have finished the whole thing so far so good and also just for good practice we will not use it this time but I'll change the status to Out of Bounds so click new rule here set variable and then I'll say out of bounds sorry status equal to Out of Bounds like this and then I can click save so now the robot will finish after it has extracted the pages that we have in the document because then this will give us an arrow we combat it for the Arrow by saying go down to this label and let me just show you I have my whole project here here I have my two original PDFs that will be in the project folder let's try to run it and see that everything actually works so here I'll just pick one of them I'll say open and now you can see we have the numbers here and my robot will end at the correct place it's that easy to split a PDF document with power automate desktop let's also say that we want to create a lock and we want to create a solution that works on several PDF documents so a list of PDFs let me just delete these those ones were the one that we extracted so we go in here let's create a simple lock that will be a list with the files extracted then we can count them and create a nice lock so what I want to do here is that I want to say create new list and then I'll drag it in here above the loop condition I will call it something I will say X extracted PDF files like this and then I will click save so I'll create it here and then each time I extract a PDF document that will be one of them then I will take this extracted PDF and add to this list up here so find and add item to list and then drag it in right after the extract PDF file pages to a new PDF file what list do I want to add them to well that will be the extracted PDF files click this Excel and what item do I want to add well that was the extracted PDF that got stored here so that is each separate PDF that I'm creating I stored into extracted PF and we will extract it to this page so find an extracted PDF and then click save so now we have a list with these items down here we will create a just a symbol doc so let's just display I have a display message to the user you can create all sorts of different logs so down here I'll just say something like um that we have splitted your for example your PDF split into and then we will have a count on our list so that will be the extracted PDF files expanded and then pick count click save and then we can say it got split into PDF files find them here and then we will just guide the user to the directory and that will be the selected PDF file up here that's where we extracted the PDF files so the selected PDF file and then just take the directory like this so now we are done with logging let's just test that everything works that we actually get a nice log I'll just pick one of them and then we'll continue with the full solution that can take multiple PDF documents with PDFs in here you can see our PDF split into six PDF files correct and we can find a directory here so far so good so we created the solution and let's expand it let me delete this again so we can see it works afterwards so what I want to do up here either I want a if you created a solution with a variable instead of this display select file dialog then you need to change it to a list of file path or I can just go up here and then I can say allow multiple selection now you can see that the variables produced that change to selected files and this will actually be a list of texts so if I just go in here I'll just say selected PDF files when I click OK here or save then this row this robot here the flow will have several arrows that is because we we are dependent on the selected PDF file and now we have the selected PDF files so here you can see we have a little bit of Errors let's fix it no need to worry so we need it for each Loop and that one will be for each one of these PDF files up here then we want everything to happen down here so I'll find a for each right in the beginning and let me just it's here and if for each just take a collection that could be our list here take the items one by one and then it finished so what value do I want to iterate I want the selected PDF files that is a list and then let's just storm into a selected file and that way we can use this selected PDF file that means that we have a list item and we can refer to that list item by the selected PDF file when we go to the next list item we refer to It Again by this name so it looks like this so now you can see since we created it up here we have no arrows now we just need to say we want to start over each time so that is for each one of the the PDF documents we started page one we set the status to okay we create a new list in fact we do everything you can argue that we want to create a final log but for now it's okay to have a lock for each PDF document feel free to change that what you can do is to click the set variable go down here press shift click the display message and then drag it inside for each so now we'll Loop each file up here into for each that is it for each Loop and then we will say for each one of the pages extract it create a log blah blah blah so let's start our solution and let's see that we can actually have it work with two PDFs I chose two and here you can see we first take the datum now we have the log six PDF files this directory now we take the contoso it looks fine everything works that is that's it if you want the next power automate lesson then click the video up here I just signed it for you see you

+ نوشته شده در  چهارشنبه ۱۴۰۲/۰۹/۰۱ساعت &nbsp توسط رضا  | 

یک شعر زیبا...
ما را در سایت یک شعر زیبا دنبال می کنید

برچسب : نویسنده : xcheater بازدید : 29 تاريخ : دوشنبه 13 آذر 1402 ساعت: 1:09