Op 4/06/2012 6:26, Parminder Kaur schreef:
<table><tr><td>The HTML image (&quot;&lt;img&gt;&quot;) tag</td><tr></table>

I'm sorry, I can't reproduce the error. See code sample + result in attachment. However, I did have to fix your HTML. I replaced <tr> by </tr> in the above HTML snippet.

I'm using the most recent versions of XML Worker and iText (the version available in the SVN trunk). Maybe you're experiencing a bug that has already been fixed.

Attachment: html2pdf.pdf
Description: Adobe PDF document

package examples.xml;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.tool.xml.XMLWorkerHelper;

public class HtmlParserTest {
        
        public static final String HTML = "<table><tr><td>The HTML image 
(&quot;&lt;img&gt;&quot;) tag</td></tr></table>";
        
        /**
         * Creates a PDF with the words "Hello World"
         * @param file
         * @throws IOException
         * @throws DocumentException
         */
        public void createPdf(File file) throws IOException, DocumentException {
                // step 1
                Document document = new Document();
                // step 2
                PdfWriter writer = PdfWriter.getInstance(document, new 
FileOutputStream(file));
                // step 3
                document.open();
                // step 4
                XMLWorkerHelper.getInstance().parseXHtml(writer, document,
                                new 
ByteArrayInputStream(HTML.getBytes("UTF-8")));
                // step 5
                document.close();
        }
        
        /**
         * Main method
         */
        public static void main(String[] args) throws IOException, 
DocumentException {
                File dir = new File("results/");
                dir.mkdirs();
                new HtmlParserTest().createPdf(new File(dir, "html2pdf.pdf"));
        }
}
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to