You might want to try to use PdfSmartCopy instead of PdfWriter - it caches stream objects.
-----Original Message----- From: Fred Cohen [mailto:f...@all.net] Sent: Thursday, March 25, 2010 9:21 AM To: itext-questions@lists.sourceforge.net Subject: [iText-questions] Producing images without duplicating them in thePDF file I am doing a conversion from HTML to PDF, trying to use the existing tools. For this particular case I have cheated and fixed the "table" entry to have columns that are reasonable for the application (as you will see below). The problem I am having now is that the output file is quite large relative to what it needs to be, and I believe it is because this approach duplicates all of the jpeg images contained in the file, which in this case turns what should be a 200K PDF file into a 3Meg PDF file. It seems to me that iText might want to create a hashtable of images so that, instead of including one after another, it only includes one of each and then points to them. I know too little about PDF to do this myself, but I am wondering if anyone else has thought through this - done it before - or if it is a simple fix to the HTML reader or PDF writer, whether it is likely to appear in an update soon... Or is there a way to do this by parsing the PDF directly? Here is sameple code as it runs reasonably well today - except for the size problem. File ff = new File(OutP);if (ff.exists()) {ff.delete();} com.itextpdf.text.Document d = new com.itextpdf.text.Document (PageSize.LETTER, 40, 40, 40, 40); try {PdfWriter.getInstance(d, new FileOutputStream (OutP));d.open (); FileReader fr = new FileReader(OutF); ArrayList elementlist = com.itextpdf.text.html.simpleparser.HTMLWorker.parseToList(fr, null); for (int i = 0; i < elementlist.size(); i++) {com.itextpdf.text.Element element = (com.itextpdf.text.Element)elementlist.get(i); if (ShowCount.equals("T")) {if (element.type() == 23) {float [] f = new float[] { 0.10f, 0.90f}; PdfPTable p;p=(PdfPTable)element;p.setWidths(f);}} d.add(element);} d.close (); } catch(Exception de) {System.err.println("Ouch!!! " + de.getMessage());return(-2);} FC - This communication is confidential to the parties it is intended to serve - Fred Cohen & Associates tel/fax: 925-454-0171 http://all.net/ 572 Leona Drive Livermore, CA 94550 Join http://groups.google.com/group/fca-announce for our mailing list ---------------------------------------------------------------------------- -- Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ 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/ ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ 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/