The code:
public File makeCitedDocument(Bitstream bitstream) throws IOException, SQLException, AuthorizeException, COSVisitorException { PDDocument document = new PDDocument(); PDDocument sourceDocument = new PDDocument(); try { Item item = (Item) bitstream.getParentObject(); sourceDocument = sourceDocument.load(bitstream.retrieve()); PDPage coverPage = new PDPage(PDPage.PAGE_SIZE_LETTER); generateCoverPage(document, coverPage, item); addCoverPageToDocument(document, sourceDocument, coverPage); document.save(tempDir.getAbsolutePath() + "/bitstream.cover.pdf"); return new File(tempDir.getAbsolutePath() + "/bitstream.cover.pdf"); } finally { sourceDocument.close(); document.close(); } }
What I'm trying to achieve after a PDF merge:
- Maintain PDF / A compliance if sourceDocument is compatible with PDF / A
- Keep bookmarks if sourceDocument contains bookmarks
- Save sourceDocument metadata (e.g. Title, Author, Subject, Keywords)
Please do not offer iText, I have already achieved this with iText, but due to licensing we need to use pdfbox. Also note that I did not write this code, this is from dspace. You can find the full code here: CitationDocument.java
source share