One of our issues when unit testing our PDF generation code is that iText
creates PDFs with fonts in an unpredictable order. This makes it impossible
to simply compare checksums of itext-generated PDF files from one change
to the next.
This is due to one particular use of HashMap internally within the PdfWriter
class. Replacing this use of HashMap with LinkedHashMap solves the problem
because LinkedHashMap iterates over its entries in the order they were
inserted. LinkedHashMap was added in JDK 1.4 so it will be compatible with
the 1.4 requirement that itext has.
The following diff fixes the issue and has been tested.
Index: itext/java/com/lowagie/text/pdf/PdfWriter.java
===================================================================
diff -u -p -r1.1.1.9 PdfWriter.java
--- itext/java/com/lowagie/text/pdf/PdfWriter.java 6 Jun 2007 23:11:39
-0000 1.1.1.9
+++ itext/java/com/lowagie/text/pdf/PdfWriter.java 26 Aug 2008 23:22:06
-0000
@@ -57,6 +57,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;
@@ -1842,7 +1843,7 @@ public class PdfWriter extends DocWriter
// [F3] adding fonts
/** The fonts of this document */
- protected HashMap documentFonts = new HashMap();
+ protected LinkedHashMap documentFonts = new LinkedHashMap();
/** The font number counter for the fonts in the document. */
protected int fontNumber = 1;
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
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