|
Hello
Bruno, Topic: Creating a PDF file using String
object with HTML content I
am getting an error (see below) when I parse my HTML string using HTMLWorker ERROR -------------- java.lang.IllegalArgumentException:
The number of columns in PdfPTable
constructor must be greater than zero.
at com.lowagie.text.pdf.PdfPTable.<init>(Unknown Source)
at com.lowagie.text.html.simpleparser.IncTable.buildTable(Unknown Source)
at com.lowagie.text.html.simpleparser.HTMLWorker.endElement(Unknown Source)
at com.lowagie.text.pdf.SimpleXMLParser.parse(Unknown Source)
at com.lowagie.text.html.simpleparser.HTMLWorker.parse(Unknown Source)
at PDF.main(PDF.java:25) -------------- CODE -------------- Transform
trans = new Transform(); String
htmlOP = trans.transform("D:\\work\\SEACR.xsl","D:\\work\\SEACR.xml"); System.out.println(htmlOP); StringReader
strReader = new StringReader(htmlOP); PdfWriter.getInstance(document,
new FileOutputStream("test.pdf")); document.open(); document.resetPageCount(); //document.add(new
Paragraph("Hi, this is your PDF file!")); HTMLWorker html = new HTMLWorker(document); html.parse(strReader); -------------- My
AIM is to create a PDF file with
the html string “htmlOP”.
Thank you very much. Regards Mazhar
Shaikh From: Mazhar Shaikh Dear Users, I have transformed my XML and XSL to a StringWriter object
like this // Transformation code StringWriter writer = new StringWriter(); transformer.transform(new StreamSource(xml), new
StreamResult(writer)); String str_with_html_tags
= writer.toString(); The result of the transformation i.e “str_with_html_tags” is then passed to
the PDF generation code. // PDF Generation code PdfWriter.getInstance(document, new
FileOutputStream("filename.pdf")); document.open(); document.add(str_with_html_tags); But as a result when I open the PDF document I could see
text with all HTML tags embedded in it. My Questions.
Note: I am using
HTML in my XSL document. Please ask me if you have any questions. Thanks and regards, Mazhar Shaikh Handy: +91 9860687474 This email may contain confidential or privileged information for the intended recipient(s) and the views expressed in the same are not necessarily the views of Zensar Technologies Ltd. If you are not the intended recipient or have received this e-mail by error, its use is strictly prohibited, please delete the e-mail and notify the sender. Zensar Technologies Ltd. does not accept any liability for virus infected mails. |
