Hi all iText cracks, many thanks for your valuable comments and advices. Based on your comments I have redesigned the application (see below): only one FileOutputStream (step 3 for the final document), step 1 and 2 uses ByteArrayOutputStream. Step 3 uses PdfWriter and PdfImportedPage instead of PdfCopy (performance enhancements). The following fact influences my design: (I guess...) I have to stamp per statement of account (page x/y, first page of a statement has a different table background template as the followintg pages within the statement). My concern: how can I prevent that the templates for the first resp. further pages are only included ONCE in the final document ? Any help would be very appreciated.
Thanks a lot for your support. Martin Step 1 (per statement: unstamped) Document document = new Document(); ByteArrayOutputStream baosUnstamped = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baosUmstamped); document.open(); PdfContentByte pdfContentByte = document.getDirectContent(); int numberOfColumns = ...; PdfPTable table = new PdfPTable(numberOfColumns); itextTable.writeSelectedRows(0, -1, ... , ... , pdfContextByte); document.close(); Step 2 (per statement: stamped) unstampedReader = new Reader(baosUmstamped.toByteArray()); ByteArrayOutputStream baosStamped = new ByteArrayOutputStream(); stamper = new PdfStamper(unstampedReader, baosStamped); int pageNum = ...; PdfContentByte underContent = stamper.getUnderContent(pageNum); PdfTemplate templateFirstPage = ...; PdfTemplate templateSecondPage = ...; /* for first page within statement of account */ underContentByte.addTemplate(templateFirstPage); /* for page two and upward within statement of account */ underContentByte.addTemplate(templateSecondPage); PdfContentByte overContent = stamper.getOverContent(pageNum); overContent.beginText(); overContent.setTextMatrix(... , ...); String pageText = ...; /* page x/y */ overContent.showText(pageText); overContent.endText(); Step 3 FileOutputStream fos = new FileOutputStream(...); Document finalDocument = new Document(); finalWriter = PdfWriter.getInstance(finalDocument, fos); /* per stamped statement */ stampedReader = new Reader(baosStamped.toByteArray()); int pageNum = ...; finalWriter.getImportPage(stampedReader, pageNum); /* for each stamped page */ ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.1t3xt.com/docs/book.php Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
