The task is to combine two different pdf files into one generated in one query. There is a method that generates a pdf file based on the received data and saves the result in HttpServletResponse. So far, for example, I want to make two ByteArrayOutputStreams from one response and eventually combine the results into one pdf file.
Getting an OutputStream
ServletOutputStream pdfOne = response.getOutputStream();
ServletOutputStream pdfTwo = response.getOutputStream();
Transform it into a byte array
ByteArrayOutputStream outputOne = new ByteArrayOutputStream();
outputOne.writeTo(pdfOne);
byte[] resultByteOne = outputOne.toByteArray();
ByteArrayOutputStream outputTwo = new ByteArrayOutputStream();
outputTwo.writeTo(pdfTwo);
byte[] resultByteTwo = outputTwo.toByteArray();
And with the help of PDFBox, I want to connect exactly two byte arrays. Everywhere there are examples of how to make merge from ready-made pdf files from the repository
And in general, can I do that?