You can call this function as below. If you have Base64 of the file, convert to bytearray and then pass it to function. If you have HTML markup of the PDF, convert to bytearray using HTMLtoPDF activity.
You can allow the user to download the merged PDF using by passing param value to View activity.
You can tweak the code and loop through the PDFs to work for your scenario. Let me know if you have any questions.
The solutions described earlier using Apache pdfbox are really great and worth trying. But in my experience, not all PEGA developers are comfortable with Java coding and in case if you are using an old PEGA version, for instance 7.1, PDFBox JARs will have to be imported into the application for the solution to work. If you want to implement the solution using only PEGA OOTB below is a suggestion which I implemented for PDF generation in PEGA 7.1.
Create an activity and create a page with class Code-PEGA-eForm(PageName example: MergePDF)
Use HTMLToPDF to generate PDF from HTML stream.
The above activity provides the PDF in byteArray form through an output parameter named PDFDocument.
Do a Property-Set after each of the HTMLToPDF activity call with code like below:
MergePDF.pyEForms(<APPEND>) = Param.PDFDocument
After calling all required HTMLToPDF call ConcatenateEForms activity on the above-created page (MergePDF here).
The final PDF byteArray will be available on the Property pyEForm of the same page.
Do a Property-Set:
Param.PDFDocument = MergePDF.pyEForm
Param.PDFName = Test.pdf
Call Code-Pega-PDF.View which will generate your final PDF.
Although the class of the above activity indicates that it is for eForm but will work perfectly fine for normal PDFs a well.
Do analyze the code of ConcatenateEForms activity as depending on your PEGA version you will get multiple functionalities available in this OOTB activity including encryption and password protection for PDF.
Note: PDFDocument parameter used by PEGA is actually the object address pointing to PDF Byte Array. So if someone wants to use a custom code instead of HTMLToPDF the final PDF can be converted to bytearray and et on a parameter to be used by PEGA.