I have a back-end Java application that grabs the contents of PDF files from a blob in the database, and puts them into a byte[] array to be able to download.
My end goal - if possible - is to append the contents of one file to another file such that a single download will display it as a single PDF file that contains the contents of both files.
For example, if one PDF file is a one-page file that says 'PDF File 1 Contents', and another PDF file is a one-page file that says 'PDF File 2 Contents' - I would like to combine the contents to a two-page PDF file that has 'PDF File 1 Contents' on the first page and 'PDF File 2 Contents' on the second page.
I though maybe I could do this by concatenating the byte[] arrays of the two files like so:
public void getDocument(HttpServletResponse response) { byte[] docContent1 = documentDao.getDocument(blah, blah, blah); byte[] docContent2 = documentDao.getDocument(blah, blah, blah); byte[] concatenatedFile = new byte[docContent1.length + docContent2.length]; System.arraycopy(docContent1, 0, concatenatedFile, 0, docContent1.length); System.arraycopy(docContent2, 0, concatenatedFile, docContent1.length, sfiDocContent2.length); HttpServletResponse response = new HttpServletResponse(); response.setContentType(blah); response.getOutputStream().write(concatenatedFile);}
However, all that is displayed after the download is the contents of docContent2.
Any suggestions?
Thank you