I was having problems getting horizontalline's working using the xml
input technique.  I have managed to get it working for my needs; however
I do not know if it is technically correct.  I post this as a possible
solution.

Passing the following xml would error out when passed to
SAXiTextHandler:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE ITEXT SYSTEM "http://itext.sourceforge.net/itext.dtd";> 
<itext creationdate="Thu Oct 02 14:56:45 CEST 2003" producer="iTextXML
by lowagie.com">
<paragraph align="Default" fontsize="14.0" leading="18"
font="Helvetica">section1</paragraph>
<newline />
<horizontalrule />
<paragraph align="Default" fontsize="14.0" leading="18"
font="Helvetica">section2</paragraph><newpage />
<chapter numberdepth="0" depth="0" indent="0.0">
     <title align="Default" leading="36.0" font="Helvetica" size="24.0"
fontstyle="normal">
     <chunk>TEST HEADER</chunk>
     </title>
</chapter>
<horizontalrule />
<newpage />
<paragraph align="Default" fontsize="14.0" leading="18"
font="Helvetica">section3</paragraph>
</itext>

The desired output is attached as a pdf (hopefully...unless sourceforge
stripped it out).


I changed the code in com.lowagie.text.xml.SAXiTextHandler (~line 389):
====================================================
if (ElementTags.HORIZONTALRULE.equals(name)) {
        TextElementArray current;
      Graphic hr = new Graphic();
      hr.setHorizontalLine(1.0f, 100.0f);
      try {
        current = (TextElementArray) stack.pop();
            current.add(hr);
            stack.push(current);
      }
      catch(EmptyStackException ese) {
        try {
                document.add(hr);
            }
            catch(DocumentException de) {
                throw new ExceptionConverter(de);
            }
      }
      return;
}
===================================================

To:
===================================================
if (ElementTags.HORIZONTALRULE.equals(name)) {
      Graphic hr = new Graphic();
      hr.setHorizontalLine(1.0f, 100.0f);
      try {
        document.add(hr);
      }
      catch(DocumentException de) {
                throw new ExceptionConverter(de);
      }
      return;
}
=====================================================

Working back through the code it appears that Section.java and
Phrase.java do not allow a GRAPHIC object to be added to them with a
.add(Object) method call.  Consequently the horizontalline was throwing
a ClassCastException error which was not getting caught properly because
the catch was only for an EmptyStackException.  So as far as I could
tell the GRAPHIC object should always use the document.add functionality
so I removed the pop/push code.  I don't pretend to know all the
intricacies of the iText code so the pop/push code may be required in
some condition I am not aware of.  

Of course it is completely possible that my xml is improperly formed for
iText and that I rewrote the java code to fit my own screwed up xml...

Cheers,
Steve Balthazor

Attachment: testres1.pdf
Description: Adobe PDF document

Reply via email to