I have two services that each return a pdf file in a byte[]. What I need is to join in the same pdf the two pdf that I generate separately in two services.
I have tried different ways of concatenating the two byte[] but all I get is that one overwrites the other.
Attempts that have not worked:
byte[] result = new byte[a.length + b.length];
// copy a to result
System.arraycopy(a, 0, result, 0, a.length);
// copy b to result
System.arraycopy(b, 0, result, a.length, b.length);
--
byte[] c = Bytes.concat(a, b);
--
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
output.write(b);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
output.write(a);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte[] out = output.toByteArray();
I would appreciate any kind of help.
Thank you very much.
EDIT. POSSIBLE SOLUTION
I have read this solution. It may not be the best, but so far it is working.