代码:
/**
* Creates a
* cited document from the given bitstream of the given item. This
* requires that bitstream is contained in item.
* <p>
* The Process for adding a cover page is as follows:
* <ol>
* <li> Load source file into PdfReader and create a
* Document to put our cover page into.</li>
* <li> Create cover page and add content to it.</li>
* <li> Concatenate the coverpage and the source
* document.</li>
* </p>
*
* @param bitstream The source bitstream being cited. This must be a PDF.
* @return The temporary File that is the finished, cited document.
* @throws java.io.FileNotFoundException
* @throws SQLException
* @throws org.dspace.authorize.AuthorizeException
*/
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();
}
}
pdf合并后我想要实现的目标:
- 如果 sourceDocument 符合 PDF/A,则保持 PDF/A 合规性
- 如果 sourceDocument 包含书签,则保留书签
- 保留 sourceDocument 的元数据(例如标题、作者、主题、关键字)
请不要建议 iText,我已经使用 iText 实现了这一点,但由于许可,我们需要使用 pdfbox 代替。另请注意,这些代码不是我写的,这是来自 dspace。你可以在这里找到完整的代码:CitationDocument.java