Posts

Showing posts with the label itext

Switch between ColumnDocumentRenderer and DocumentRenderer in same page?

Image
Switch between ColumnDocumentRenderer and DocumentRenderer in same page? I was testing few things with iText7 and I have a scenario where I need to have DocumentRenderer paragraph at the top and then start the ColumnDocumentRender with 2 columns right below it on the same page. The problem I am having is when I change the content on same page it overlaps content from DocumentRenderer with content from ColumnDocumentRenderer. I believe it is because one render does not know about the other render and contents starts from the top of the page. I followed this tutorial but it only shows how to add content to the next page. It does say we'll have to instruct iText not to flush the content to the OutputStream But can anyone show me exactly how we can achieve this? public void createPdf(String dest) throws IOException { PdfDocument pdf = new PdfDocument(new PdfWriter(dest)); Document document = new Document(pdf); Paragraph p = new Paragraph() .add("Be prepared t...

Using iText 2.1.7 to merge large PDFs

Using iText 2.1.7 to merge large PDFs I am using an older version of iText (2.1.7) to merge PDFs. Because that is the last version under the MPL available to me. I cannot change this. Anyways. I am trying to merge multiple PDFs. Everything seems to work ok, but when I go over about 1500 pages, then the generated PDF fails to open (behaves as if it is corrupted) This is how I am doing it: private byte mergePDFs(List<byte> pdfBytesList) throws DocumentException, IOException { Document document = new Document(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PdfCopy copy = new PdfCopy(document, outputStream); document.open(); for (byte pdfByteArray : pdfBytesList) { ByteArrayInputStream readerStream = new ByteArrayInputStream(pdfByteArray); PdfReader reader = new PdfReader(readerStream); for (int i = 0; i < reader.getNumberOfPages(); ) { copy.addPage(copy.getImportedPage(reader, ++i)); } co...