use of com.itextpdf.kernel.utils.PdfMerger in project Rolls-Royce by EntryDSM.
the class ApplicationPdfGenerator method generateApplicationPdf.
private byte[] generateApplicationPdf(User user, Score score) {
PdfData data = pdfDataConverter.applicationToInfo(user, score);
ByteArrayOutputStream[] outputStreams = getTemplateFileNames(user).parallelStream().map(template -> templateProcessor.convertTemplateIntoHtmlString(template, data.toMap())).map(pdfProcessor::convertHtmlToPdf).toArray(ByteArrayOutputStream[]::new);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PdfDocument mergedDocument = new PdfDocument(new PdfWriter(outputStream));
PdfMerger pdfMerger = new PdfMerger(mergedDocument);
Document document = new Document(mergedDocument);
for (ByteArrayOutputStream pdfStream : outputStreams) {
PdfDocument pdfDoc = getPdfDocument(pdfStream);
mergeDocument(pdfMerger, pdfDoc);
}
for (int i = 1; i <= mergedDocument.getNumberOfPages(); i++) {
document.showTextAligned(new Paragraph(String.format("- %s -", i)), 300, 25, i, TextAlignment.CENTER, VerticalAlignment.BOTTOM, 0);
}
document.close();
return outputStream.toByteArray();
}
use of com.itextpdf.kernel.utils.PdfMerger in project Rolls-Royce by EntryDSM.
the class PdfProcessor method concat.
public ByteArrayOutputStream concat(ByteArrayOutputStream first, ByteArrayOutputStream second) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PdfDocument mergedDocument = new PdfDocument(new PdfWriter(outputStream));
PdfMerger merger = new PdfMerger(mergedDocument);
PdfDocument firstDocument = getPdfDocument(first);
PdfDocument secondDocument = getPdfDocument(second);
mergeDocument(merger, firstDocument);
mergeDocument(merger, secondDocument);
mergedDocument.close();
return outputStream;
}
Aggregations