Skip to main content

Notifications

Community site session details

Community site session details

Session Id : pEfSpNJ1Rm28+euGFGPC3t
Power Automate - Power Automate Desktop
Answered

how to combine pdf files from folder A and folder B and put them into folder C

Like (0) ShareShare
ReportReport
Posted on 21 Mar 2024 14:49:16 by 24

because of the workload and I found automation using PAD, here I want to combine the pdf files from folder A and folder B then put them into folder C. in the order of pdf files from folder A above and pdf files from folder B below
The following is an illustration of the contents of folder, folder B, and folder C

Folder A
1234_SEP.pdf
1235_SEP.pdf
etc

 

folder B
1234.pdf
1235.pdf
etc

 

C folder
with the new file name 1234.pdf (1234_SEP.pdf above and 1234.pdf below)

 

I hope that makes sense, Thanks in advance for your help

  • lagibingung Profile Picture
    24 on 21 Mar 2024 at 18:00:31
    Re: how to combine pdf files from folder A and folder B and put them into folder C

    this works fine
    Thank you to all of you

    sorry if it makes you confused

  • lagibingung Profile Picture
    24 on 21 Mar 2024 at 18:00:03
    Re: how to combine pdf files from folder A and folder B and put them into folder C

    this works fine
    Thank you to all of you

    sorry if it makes you confused

  • VishnuReddy1997 Profile Picture
    2,322 Super User 2025 Season 1 on 21 Mar 2024 at 17:43:54
    Re: how to combine pdf files from folder A and folder B and put them into folder C

    Hi @lagibingung ,

     

    In Merge PDF Files action, please reverse the variables.

    FolderBfiles variable followed by FolderAFiles

     

    (Note:- if you got your solution you can mark as solution and gives kudos)

     

    Thanks & Regards

    Vishnu Reddy

  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,105 Super User 2025 Season 1 on 21 Mar 2024 at 17:43:27
    Re: how to combine pdf files from folder A and folder B and put them into folder C

    @lagibingung 

     

    Deenuji_0-1711043200411.png

     

    Got it!

    In the merge pdf action swap the variables. Now We have mentioned AFolderFiles[Counter].Fullname right. Now first place BFolderFiles[Counter].Fullname and move AFolderFiles to last.

     

  • lagibingung Profile Picture
    24 on 21 Mar 2024 at 17:35:36
    Re: how to combine pdf files from folder A and folder B and put them into folder C

    I'm sorry, in folder A I forgot to change 1234SEP.pdf to 1234_SEP.pdf, maybe that's why there are no merged files in the output folder

    now the pdf has been combined and named accordingly

    The problem this time is, the pdf in folder A is located on page 2 while the pdf in folder B is located on the first page, can the mergedpdf feature on PAD make the pdf file in folder A located on the first page?

  • Deenuji_Loganathan_ Profile Picture
    6,105 Super User 2025 Season 1 on 21 Mar 2024 at 17:25:32
    Re: how to combine pdf files from folder A and folder B and put them into folder C

    @lagibingung 
    Pls share screenshot of folder A and B if possible? I can assist you in more appropriate way by finetune my above code.

     
  • VishnuReddy1997 Profile Picture
    2,322 Super User 2025 Season 1 on 21 Mar 2024 at 17:14:58
    Re: how to combine pdf files from folder A and folder B and put them into folder C

    Hi @lagibingung ,

     

    Both works bit similar. Just try my new updated solution.

    If it doesn't work, we will see.

    Let me know whether it worked or not.

     

    (Note:- if you got your solution you can mark as solution and gives kudos)

     

    Thanks & Regards

    Vishnu Reddy

  • VishnuReddy1997 Profile Picture
    2,322 Super User 2025 Season 1 on 21 Mar 2024 at 17:11:28
    Re: how to combine pdf files from folder A and folder B and put them into folder C

    Hi @lagibingung ,

     

    Please find the solution for naming the file after merging.

    VishnuReddy1997_0-1711041033530.png

     

    Please copy the updated below code to your flow.

     

    Code:

     

    Folder.GetFiles Folder: $'''C:\\Users\\vr79540\\OneDrive - Cyient Ltd\\Desktop\\Power Automate Desktop\\Practice\\Combine PDFS\\Folder A''' FileFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> FolderA_Files
    Folder.GetFiles Folder: $'''C:\\Users\\vr79540\\OneDrive - Cyient Ltd\\Desktop\\Power Automate Desktop\\Practice\\Combine PDFS\\Folder B''' FileFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> FolderB_Files
    SET Counter TO 0
    LOOP FOREACH CurrentItem IN FolderA_Files
    Text.SplitText.SplitWithDelimiter Text: FolderA_Files[0].Name CustomDelimiter: $'''_''' IsRegEx: False Result=> TextList
    Pdf.MergeFiles PDFFiles: $'''{ \"%FolderA_Files[Counter].FullName%\", \"%FolderB_Files[Counter].FullName%\" }''' MergedPDFPath: $'''C:\\Users\\vr79540\\OneDrive - Cyient Ltd\\Desktop\\Power Automate Desktop\\Practice\\Combine PDFS\\Folder C\\%TextList[0]%.pdf''' IfFileExists: Pdf.IfFileExists.AddSequentialSuffix PasswordDelimiter: $''',''' MergedPDF=> MergedPDF
    Variables.IncreaseVariable Value: Counter IncrementValue: 1
    END

     

    (Note:- if you got your solution you can mark as solution and gives kudos)

     

    Thanks & Regards

    Vishnu Reddy

  • lagibingung Profile Picture
    24 on 21 Mar 2024 at 17:10:34
    Re: how to combine pdf files from folder A and folder B and put them into folder C

    can the script be made from the script @Deenuji  described?

  • lagibingung Profile Picture
    24 on 21 Mar 2024 at 17:08:51
    Re: how to combine pdf files from folder A and folder B and put them into folder C

    OK, thanks for the explanation, here I start to understand how your script works

    Here there is a problem with the output folder after merging files, there are no merged PDF files there

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,653 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard