use of com.itextpdf.text.pdf.PdfCopy in project ASCIIGenome by dariober.
the class Pdf method appendPdf.
/**
* Append pdf file `in` to pdf file `dest`
* @throws IOException
* @throws DocumentException
*/
private void appendPdf(File in, File dest) throws IOException, DocumentException {
if (!dest.exists()) {
Files.move(Paths.get(in.getAbsolutePath()), Paths.get(dest.getAbsolutePath()));
return;
}
File template = Utils.createTempFile(".template.", ".pdf");
;
template.deleteOnExit();
Files.copy(Paths.get(dest.getAbsolutePath()), Paths.get(template.getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING);
Document document = new Document();
FileOutputStream outputStream = new FileOutputStream(template);
PdfCopy copy = new PdfSmartCopy(document, outputStream);
document.open();
PdfReader reader0 = new PdfReader(dest.getAbsolutePath());
copy.addDocument(reader0);
reader0.close();
PdfReader reader = new PdfReader(in.getAbsolutePath());
copy.addDocument(reader);
reader.close();
document.close();
Files.move(Paths.get(template.getAbsolutePath()), Paths.get(dest.getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING);
}
Aggregations