@Override public ByteArrayOutputStream buildPdfOutputStream(byte[] content) throws IOException, DocumentException, BadPdfFormatException { List<byte[]> contents = new ArrayList<>(); contents.add(content); return buildPdfOutputStream(contents); }
/** * Generate pdf for sending response using itext * * @param reportFileFullName * @return * @throws IOException * @throws DocumentException * @throws BadPdfFormatException */ protected ByteArrayOutputStream generatePdfOutStream(String reportFileFullName) throws IOException, DocumentException, BadPdfFormatException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); // we create a reader for a certain document PdfReader reader = new PdfReader(reportFileFullName); reader.consolidateNamedDestinations(); // step 1: creation of a document-object Document document = new Document(reader.getPageSizeWithRotation(1)); // step 2: we create a writer that listens to the document PdfCopy writer = new PdfCopy(document, baos); // step 3: we open the document document.open(); // we retrieve the total number of pages int n = reader.getNumberOfPages(); // step 4: we add content PdfImportedPage page; for (int i = 0; i < n;) { ++i; page = writer.getImportedPage(reader, i); writer.addPage(page); } writer.freeReader(reader); // step 5: we close the document document.close(); return baos; }
/** * Builds a PDF ByteArrayOutputStream that can be returned in the response. * * @param content byte[] used to build the PDF output stream * @return PDF ByteArrayOutputStream * @throws IOException * @throws DocumentException * @throws BadPdfFormatException */ public ByteArrayOutputStream buildPdfOutputStream(byte[] content) throws IOException, DocumentException, BadPdfFormatException;
/** * Builds a PDF ByteArrayOutputStream that can be returned in the response. * * @param contents List of byte arrays used to build the PDF output stream * @return PDF ByteArrayOutputStream * @throws IOException * @throws DocumentException * @throws BadPdfFormatException */ public ByteArrayOutputStream buildPdfOutputStream(List<byte[]> contents) throws IOException, DocumentException, BadPdfFormatException;