I know this is a part of iText that is not primary, but I am attempting to
add HTML to a Pdf Paragraph based on bits and pieces of advice I found
through the mailing list and the book.  I put together the test class that I
have attached and I am having some problems.  I wanted to see if there was
any quick advice on how I am approaching this.  (note: the purpose of the
test class is specifically to add small html snippets to a specific section
of an existing PDF.  A form field was placed on the Pdf Template as a place
holder for use in locating that specific section of the PDF)

It is correctly adding the HTML to the location on the PDF document that I
want it to, but the "ul" tags have no bullets.  I tried "ol" tags and they
also have no numbers.  I made multiple attempts at the styles (you may
notice that the styles below are mostly copied straight from one of the
mailing list posts), but i can't seem to get the bullets on the list to
show.  it is simply adding the individual "li" lines to the PDF.  

Am I adding it incorrectly to a paragraph?  Am I using the ColumnText
incorrectly?  Am I not using the right styles?

Thanks for any advice!

//************************************
I am calling the class like this (where stamper is a PdfStamper, forms =
stamper.getAcroFields()):
// ...other code to fill in form fields

                // test html for testing HtmlWorker
                String html = "<p>list of items</p><ul><li>item 1</li><li>item
2</li><li>item three</li></ul>";
                
                HtmlToPdf parser = new HtmlToPdf();
                parser.addHtmlToPdfContentByte(html, stamper.getOverContent(1),
form.getFieldPositions("body"));

// ... other code to flatten and close stamper.


//************************************
import java.io.StringReader;
import java.util.ArrayList;

import com.lowagie.text.Element;
import com.lowagie.text.Paragraph;
import com.lowagie.text.html.simpleparser.HTMLWorker;
import com.lowagie.text.html.simpleparser.StyleSheet;
import com.lowagie.text.pdf.ColumnText;
import com.lowagie.text.pdf.PdfContentByte;

public class HtmlToPdf {

        
        /**
         * @param html html text
         * @param cb send in stamper.getOverContent(1)
         * @param pos send in form.getFieldPositions(<name of placeholder form
field>)
         */
        public void addHtmlToPdfContentByte(String html, PdfContentByte cb, 
float[]
pos) {
                Paragraph paragraph = new Paragraph();
                StyleSheet styles = createDefaultStyleSheet();
                
                cb.beginText();
                ColumnText c1 = new ColumnText( cb );
                c1.setSimpleColumn( pos[1] , pos[2] , pos[3] , pos[4] , 0 ,
Element.ALIGN_JUSTIFIED );
                try {
                        ArrayList htmlObjs = HTMLWorker.parseToList(new 
StringReader(html),
styles);
                        for (int k = 0; k < htmlObjs.size(); ++k) {
                                paragraph.add((Element)htmlObjs.get(k));
                        }
                        c1.addElement( paragraph ); 
                        cb.endText();
                        c1.go(); 
                } catch (Exception e) {
                        throw new RuntimeException("HtmlToPdf: Could not parse 
HTML",e);
                }
                
        }
        
        private StyleSheet createDefaultStyleSheet() {
                StyleSheet styles = new StyleSheet();
                
                styles.loadTagStyle("ul", "face", "Times");
                styles.loadTagStyle("ul", "size", "25px");
                styles.loadTagStyle("ul", "leading", "15f");
                styles.loadTagStyle("ul", "list-style-type", "square");
                styles.loadTagStyle("li", "face", "Times");
                styles.loadTagStyle("li", "size", "25px");
                styles.loadTagStyle("li", "leading", "15f");
                styles.loadTagStyle("p", "face", "Times");
                styles.loadTagStyle("p", "size", "11px");
                styles.loadTagStyle("p", "leading", "12f");
                styles.loadTagStyle("p", "spacingAfter", "6x"); 

                return styles;
        }
}
//************************************

-- 
View this message in context: 
http://www.nabble.com/HTML-to-Pdf-Paragraph-Using-ColumnText----Parsing-issue.-tp18560759p18560759.html
Sent from the iText - General mailing list archive at Nabble.com.


-------------------------------------------------------------------------
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

Do you like iText?
Buy the iText book: http://www.1t3xt.com/docs/book.php
Or leave a tip: https://tipit.to/itexttipjar

Reply via email to