String htmlString = "<h1>Ãœberschrift-h1</h1>
<h4>Ãœberschrift-h4</h4>" +
"<table border=1><tr><td>Testzeile1</td></tr><tr><td>Testzeile2</td></tr></table>" +
"Text ohne HTML-Tags
" +
"[url="http://www.cad.de"]Link[/url]
" +
"<HTML>" +
"<HEAD><TITLE>Foren auf CAD.de, Pro ENGINEER</title>" +
"<META HTTP-EQUIV=Content-Type CONTENT=text/html; charset=ISO-8859-1>" +
"</HTML>";
// create the document
com.lowagie.text.Document document = new com.lowagie.text.Document(PageSize.A4, 80, 50, 30, 65 );
// get mem stream
FileOutputStream fos = new FileOutputStream( "C:\...\test.pdf" );
BufferedOutputStream ms = new BufferedOutputStream(fos);
// need the PdfWriter for some settings
PdfWriter myWriter = PdfWriter.getInstance(document, ms);
// this is for letting the memory stream open when closing the document
myWriter.setCloseStream(false);
document.open();
HTMLWorker worker = new HTMLWorker(document);
StringReader sReader = new StringReader(htmlString);
// get the list of tags in the html document
ArrayList list = HTMLWorker.parseToList(sReader,null);
PdfContentByte byt = myWriter.getDirectContent();
// need columnText to automatically jump to a new line if end of Line is reached
ColumnText text = new ColumnText(byt);
text.setSimpleColumn( document.left(),document.bottom(),document.right(),document.top() );
for(int i = 0; i<list.size() ; i++){
text.addElement((com.lowagie.text.Element)list.get(i));
}
// write the elements to the document…
text.go();
document.close();