If PDFSET does not works well, you can do the merging using a client application in a server side language like (eg- Java,Node.js).
Write a RESTlet to grab PDFs of record and the attached PDFs. RESTlet will return the PDF in base64 format.
Next, step would be to fetch the PDFs in client application and decode it from base64 and create PDFs. Then using process APIs in client application merge the PDFs using pdftk
PDFtk is a command line tool so you can fairly invoke it using process APIs in your programming language
Below is an example of process APIs in Node.js
var spawn = require('child_process').spawn;
var pdftk = spawn('pdftk', "invoice.pdf attachment.pdf cat output out1.pdf".split(" "));
pdftk.on('close', function (code) {
if(code !==0){
return console.log('Failed PDF with code: ' + code);
}
return console.log ('All good');
});
Below is a Java snippet of Process APIs
Process process = new ProcessBuilder("pdftk","invoice.pdf", "attachment.pdf", "cat", "output", "merged.pdf").start();
errorStream = process.getErrorStream();
errorMessage = readInputStream(errorStream);
if(process.exitValue() == 0) {
trace("successful :)");
}