Skip to main content

Notifications

Community site session details
Power Automate - Power Automate Desktop
Answered

Merge pdf with Same name

Like (0) ShareShare
ReportReport
Posted on 13 Feb 2024 10:06:50 by 17

Hi I'm quite new to power automate please help me.

 

I need to merge 2 files that have the same name but from different folder. And then rename the merge file with the same name in a different folder 

 

Most tutorial shows how to merge many files from 1 folder so I'm blank.

  • SSVRAJESH Profile Picture
    12 on 05 Apr 2024 at 09:06:07
    Re: Merge pdf with Same name

    Hi @Hasya 

     

    My requirement is similar to your case.

     

    Select the files in SharePoint from folder A and folder B and folder C based on file name and merge into single pdf and saved the merged PDF into folder D with the name of file name in Power automate.

     

    if you have solution please help me on this

  • Hasya Profile Picture
    17 on 19 Feb 2024 at 13:44:56
    Re: Merge pdf with Same name

    Thank you alll all the tips arevery helpful. my flow now work just fine 😁

  • Verified answer
    eetuRobo Profile Picture
    3,253 Super User 2025 Season 1 on 19 Feb 2024 at 11:48:20
    Re: Merge pdf with Same name

    I think the problem there is now two lists inside a list and PDF files input is expecting one list/array.

    Since MergeFile1 and MergeFile2 are arrays and they are surrounded by %[]% array syntax.

    So if you put %[MergeFile1[0], MergeFile2[0]]% then it should work since its taking first item from both lists and not whole list from both variables.


    And as you said you one two pdfs to be merged and not every pdf from both folders into one file.
    So you need to loop the MergeFile lists and merge them one by one. I made example flow assuming the folder lists have the exact same files in same order. 

     

    eetuRobo_0-1708343034634.png

    Folder length conditions are for checking is one of the folders has more files and there for loop doesn't go in to error.

    PDF action:

    eetuRobo_1-1708343166381.png

  • Verified answer
    MichaelAnnis Profile Picture
    5,721 Super User 2025 Season 1 on 18 Feb 2024 at 16:24:28
    Re: Merge pdf with Same name

    I couldn’t get the syntax to work either, that’s why I opted to use a list. 

    create the list first, before the 1st loop, then clear the list in the first loop, and use the “add to list” to add each file, then merge the list together. 

  • Hasya Profile Picture
    17 on 18 Feb 2024 at 13:32:23
    Re: Merge pdf with Same name

    i doesn't seem to work for me any idea why?

    i use %[MergeFile1,Mergefile2]%

    Hasya_0-1708263072429.png

     

  • Verified answer
    MichaelAnnis Profile Picture
    5,721 Super User 2025 Season 1 on 14 Feb 2024 at 16:22:27
    Re: Merge pdf with Same name

    I actually just set this up for a client:

     

    The parts I didn't share:

    Variables.CreateNewList List=> FilesToMerge
    SET pdfFilesPath TO $'''C:\\Users\\micha\\OneDrive - Peak Digital Transformations LLC\\Documents\\Clients\\Forge\\Audit\\Saved PDF Files'''
    SET pdfFilesPathSchedules TO $'''C:\\Users\\micha\\OneDrive - Peak Digital Transformations LLC\\Documents\\Clients\\Forge\\Audit\\Saved PDF Files\\Schedules'''
    SET pdfFilesPathNotes TO $'''C:\\Users\\micha\\OneDrive - Peak Digital Transformations LLC\\Documents\\Clients\\Forge\\Audit\\Saved PDF Files\\Notes'''
    SET pdfFilesPathMerged TO $'''C:\\Users\\micha\\OneDrive - Peak Digital Transformations LLC\\Documents\\Clients\\Forge\\Audit\\Saved PDF Files\\Merged'''

     

    Create New List -> FilesToMerge

    Set Folder1 (I had it as pdfFilesPathSchedules)

    Set Folder2 (I had this as pdfFilesPathNotes)

    Set MergeFolder (I had this as pdfFilePathMerged)

    MichaelAnnis_0-1707927509218.png

     

    So, this basically reads all the files from the first folder and only merges them if there is matching file in the second folder.

     

    Hope this helps.

     

    Here is the code for lines 6 and on...I don't want to share the folder variables...don't forget to create the list up front:
    Folder.GetFiles Folder: pdfFilesPathSchedules FileFilter: $'''*''' 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 PDFSchedule IN Files
    Variables.ClearList List: FilesToMerge
    SET PDFNotes TO $'''%pdfFilesPathNotes%\\%PDFSchedule.Name%'''
    Variables.AddItemToList Item: PDFNotes List: FilesToMerge
    Variables.AddItemToList Item: PDFSchedule List: FilesToMerge
    IF (File.IfFile.DoesNotExist File: PDFNotes) THEN
    NEXT LOOP
    END
    # If PDFNotes doesn't exist, skip
    SET PDFMerged TO $'''%pdfFilesPathMerged%\\%PDFSchedule.Name%'''
    Pdf.MergeFiles PDFFiles: FilesToMerge MergedPDFPath: PDFMerged IfFileExists: Pdf.IfFileExists.Overwrite PasswordDelimiter: $''',''' MergedPDF=> MergedPDF
    File.Move Files: PDFSchedule Destination: $'''%pdfFilesPathSchedules%\\Processed''' IfFileExists: File.IfExists.Overwrite MovedFiles=> MovedFiles
    File.Move Files: PDFNotes Destination: $'''%pdfFilesPathNotes%\\Processed''' IfFileExists: File.IfExists.Overwrite MovedFiles=> MovedFiles
    END


     

    Good luck!

     

     

  • eetuRobo Profile Picture
    3,253 Super User 2025 Season 1 on 14 Feb 2024 at 13:44:33
    Re: Merge pdf with Same name

    I think you don't even need to have double \ (so forget what I first suggested)

    I got it to work like this without problems with variables: 

    eetuRobo_1-1707918194399.png


    Can you share screenshots of how your flow looks and the error you get

  • Hasya Profile Picture
    17 on 14 Feb 2024 at 10:34:02
    Re: Merge pdf with Same name

    Thank you it's very informative. I tried using that for variable but I doesn't work. I need the file from many different folders. So I would be helpful to have easy option to change.

     

  • eetuRobo Profile Picture
    3,253 Super User 2025 Season 1 on 13 Feb 2024 at 10:39:27
    Re: Merge pdf with Same name

    Try it like this:

    eetuRobo_1-1707820713637.png

     

    So put the file paths inside %[]%
    %['pdfPath1', 'pdfPath2']%
    and in the PDF files change the \ to be double \\

     

    Thats how I got it to work atleast.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,743 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,079 Most Valuable Professional

Leaderboard