I am trying to create a Power Automate flow that will open a PDF, move the last page to the front, then save and close. The trigger is moving the PDF to a sharepoint folder. I've tried but am struggling with success. Any ideas? Thanks!
Hi @dwells1,
You can use this scenario:
-
Let's say I have a PDF file with 4 pages and want to move page 4 before page1;
-
This is my flow. I'm using 2 Plumsail actions there: Split PDF and Merge PDF. I separate first 3 pages and the page 4, then combine the first 3 pages to get a single file and finally create a new PDF with the page 4 in the beginning of the result PDF.
Please give it a try.
Best regards,
Petr
Plumsail team
Hi Petr,
The PDFs will have a different number of pages each time, so that would need to be dynamic. Can I set that up?
Thanks
Hi @dwells1,
Yes, it's possible
- You need to count the number of pages in the source PDF. Add Compose action and this expression.
sub(length(split(replace(base64ToString(outputs('Get_file_content')?['body']['$content']), 'Type/Pages', ''), 'Type/Page')),1)
- Add an integer variable to get the number of pages without the last page.
- Finally, replace all static page number values in the Plumsaill actions.
This is how the entire flow looks like
Best regards,
Petr
Plumsail team
Hi Petr,
Which action is the last Plumsail action before the Apply to Each? The "Create a pdf file with all pages without the last one"? When I add a "Merge PDF" the available field is different. It says "Content Item - 1", not "Content". If I enter Result files item, it automatically puts that in an "Apply to each".
Hi @dwells1,
It is Merge PDF action, click on the button, remove all brackets and insert dynamic content from Get all pages without the last one
Best regards,
Petr
Plumsail team
Got it.
In the Apply to each output, which content do I choose? One of the circled?
Then in the "Merge PDF with all pages with the last one", do I choose "Result files item" from "Get the last page" or "Get all pages without the last one"?
This keeps adding another apply to each. I hate to be so needy, but can you show which dynamic content exactly is needed for all fields in the Apply to each?
Thanks!
Hi @dwells1,
The logic is that I want to merge the last page and all the pages without the last one.
The apply to each section is added automatically when I select the Merge PDF action to merge the last page and the rest of the document. Please check out the attached video.
Best regards,
Petr
Plumsail team
I figured it out. Success!! Thank you so much for the help!!