Search in sources :

Example 1 with PdfMerger

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();
}
Also used : PdfMerger(com.itextpdf.kernel.utils.PdfMerger) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 2 with PdfMerger

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;
}
Also used : PdfMerger(com.itextpdf.kernel.utils.PdfMerger) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument)

Aggregations

PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)2 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)2 PdfMerger (com.itextpdf.kernel.utils.PdfMerger)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Document (com.itextpdf.layout.Document)1 Paragraph (com.itextpdf.layout.element.Paragraph)1