Hello.

The basic jist is how to render HTML within a table structure of a PDF, 
where the HTML is embedded in an XML file and parsed via SAXmyHandler.

I'm posting this question to 
        1)check if someone's already done this 
or 
        2)get some validation that I'm on the write track. 
I'll preface the question by saying I'm not as experienced with XML and 
the parsers as I would like to be. My code is built off the Romeo and 
Juliet example. 

I'm parsing the xml file via these calls.
                        SAXParser parser = SAXParserFactory.newInstance
().newSAXParser(); 
                        parser.parse("data.xml", new 
testArchiveMergeBO().getXmlHandler(document));

I have written a tagmap.xml and implemented it in a class that extends 
TagMap. My tag class is initialized in a class MyHandler (extending 
SAXmyHandler) - same as the example. Here's a portion of that tagmap.xml 
file
        <tag name="table" alias="DATA_T">
                <attribute name="columns" value="2" />
                <attribute name="align" value="Left" />
                <attribute name="width" value="100%" />
                <attribute name="widths" value="50;50" />
                <attribute name="cellpadding" value="1" />
                <attribute name="cellspacing" value="0" />
                <attribute name="offset" value="0" />
                <attribute name="bordercolor" value="#000000"/>
                <attribute name="borderwidth" value="0.2"/>
                <attribute name="left" value="false"/>
                <attribute name="right" value="false"/>
                <attribute name="top" value="false"/>
                <attribute name="bottom" value="true"/>
        </tag>
        <tag name="row" alias="DATA_R">
                <attribute name="horizontalalign" value="Left" />
                <attribute name="verticalalign" value="Middle" />
        </tag>
        <tag name="cell" alias="DATA_C">
                <attribute name="horizontalalign" value="Left" />
                <attribute name="verticalalign" value="Middle" />
                <attribute name="bordercolor" value="#000000"/>
                <attribute name="borderwidth" value="0.2"/>
                <atttibute name="leading" value="1"/>
                <attribute name="left" value="false"/>
                <attribute name="right" value="false"/>
                <attribute name="top" value="false"/>
                <attribute name="bottom" value="true"/>
        </tag>
        <tag name="paragraph" alias="P_BOLD">
                <attribute name="size" value="8" />
                <attribute name="fontstyle" value="bold"/>
                <attribute name="leading" value="10"/>
        </tag>
        <tag name="paragraph" alias="P_REG">
                <attribute name="size" value="8" />
                <attribute name="leading" value="10"/>
        </tag>

All the same here, as in the Romeo and Juliet example.....

However, my data.xml contains embedded HTML
        <DATA_T>
                <DATA_R>
                        <DATA_C><P_REG>Some generic rich text field</P_REG
></DATA_C>
                        <DATA_C>
                        <P_BOLD>
                        <hr/><b>this is bold text</b><br></br><font color=
"red">Red Text</font>
                        </P_BOLD>
                        </DATA_C>
                </DATA_R>
        </DATA_T>

The application has about 100 different pages, so I chose the parser 
method (vs building the document and adding each element in code) because 
I wanted to have a consistent look/feel that the tagmap would generate. 

However, had I chose to build the document by hand in code, I would have 
been able to use the utility class HtmlWorker that will render the desired 
HTML inside a table (quite easily might I add).

                        StyleSheet st = new StyleSheet();
                        String html = new String("<hr/><b>this is bold 
text</b><br></br><font color="red">Red Text</font>");
                        StringReader sr = new StringReader(html);
                        ArrayList p = HTMLWorker.parseToList(sr, st);
                        for (int k=0;k<arrayList.size();++k) {
                                document.add((Element) arrayList.get(k));
                        }

Should I add the desired/allowable HTML tags (i.e. <b>,<hr><font>) in the 
tagmap? or should I capture those tag inside the startElement and 
endElement overridden methods of MyHandler (and do what HTMLWorker does)? 
or is there another means to solve this.

Just asking before I delve too far into it.

Thanks in advance,
Scott


Date: Wed, 8 Apr 2009 17:44:36 +0100
From: Paulo Soares <[email protected]>
Subject: Re: [iText-questions] Allow Rich Text Formatting in a field
To: Post all your questions about iText here
                 <[email protected]>
Message-ID:
 <[email protected]>
Content-Type: text/plain; charset="us-ascii"

 

> -----Original Message-----
> From: Greg Orton [mailto:[email protected]] 
> Sent: Wednesday, April 08, 2009 5:20 PM
> To: [email protected]
> Subject: [iText-questions] Allow Rich Text Formatting in a field
> 
> I'm trying to include rich text formatting in on a PDF text 
> field so I can have dynamic text with some words bold and 
> italicized within the text. I am using Acrobat to create my template.
> 
> For example: Some text should be <i>italic</i> and other text 
> to be <b>bold</b>
> 
> I've found posts regarding iText not supporting this feature 
> as of last year:
> http://www.nabble.com/forum/ViewPost.jtp?post=16397594&framed=y
>

It's still not supported.
 
> I also found a tutorial showing how to Create and change 
> RichText form fields
> http://www.crionics.com/tutorials/123-template_rtf_fields.html
> 

All you have to do is to buy the crionics product, it's not in any way 
related to iText and I don't even know what's the relevance of it in the 
iText mailing list.

> How can I include rich text within a field without having the 
> same formatting on the entire field?
> 

iText doesn't support rich text.

Paulo

Email Classification: KeyCorp Public



*******************************************************************************
This communication may contain privileged and/or confidential information. It
is intended solely for the use of the addressee. If you are not the intended
recipient, you are strictly prohibited from disclosing, copying, distributing
or using any of this information. If you received this communication in error,
please contact the sender immediately and destroy the material in its entirety,
whether electronic or hard copy. This communication may contain nonpublic 
personal
information about consumers subject to the restrictions of the 
Gramm-Leach-Bliley Act. You may not directly or indirectly reuse or redisclose
such information for any purpose other than to provide the services for which
you are receiving the information.

127 Public Square, Cleveland, OH 44114
*******************************************************************************


If you prefer not to receive future e-mail offers for products or services from 
Key 
send an e-mail to mailto:[email protected] with 'No Promotional E-mails' in 
the 
SUBJECT line.
------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
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

Reply via email to