Hi All,

I am facing one problem , I am using the following library in my program to
convert Html to pdf.

itextpdf.jar - 5.4.1 version

xmlworker - 5.4.1 version

I tested my code for so many HTMLs and it is working fine, but one of the
HTMLs is not worning and throwing the following exception.. Please look
into that and let mw know if you guys know any sollution.

java.lang.IllegalArgumentException: Element not allowed.  at
com.itextpdf.text.pdf.ColumnText.addElement(ColumnText.java:471)
 at com.itextpdf.text.pdf.PdfPCell.addElement(PdfPCell.java:283)
 at com.itextpdf.tool.xml.html.table.TableData.end(TableData.java:151)
 at
com.itextpdf.tool.xml.html.AbstractTagProcessor.endElement(AbstractTagProcessor.java:189)
 at
com.itextpdf.tool.xml.pipeline.html.HtmlPipeline.close(HtmlPipeline.java:206)
 at com.itextpdf.tool.xml.XMLWorker.endElement(XMLWorker.java:141)
 at com.itextpdf.tool.xml.parser.XMLParser.endElement(XMLParser.java:395)
 at
com.itextpdf.tool.xml.parser.state.ClosingTagState.process(ClosingTagState.java:70)
 at
com.itextpdf.tool.xml.parser.XMLParser.parseWithReader(XMLParser.java:235)
 at com.itextpdf.tool.xml.parser.XMLParser.parse(XMLParser.java:213)
 at
com.cisco.wem.transformation.HtmlProcessor.generatePDF(HtmlProcessor.java:1728)
 at
com.cisco.wem.transformation.HtmlProcessor.processHtml(HtmlProcessor.java:292)
 at
com.cisco.wem.transformation.HtmlProcessor.execute(HtmlProcessor.java:207)
 at com.cisco.wem.transformation.HtmlProcessor.run(HtmlProcessor.java:1451)
 at java.lang.Thread.run(Thread.java:662)

*I saw one of the blogs and they said to use the following snippet but I am
not sure where to use that in my code*

for (Element e : elements) {
     if (!ColumnText.isAllowedElement(e))
         continue;
     // do stuff
}

*This is my code:*

public String generatePDF(String tempFolder,String
completeHtmlFilePath,NodeBO renditionRequestBO)throws
FileNotFoundException, IOException, DocumentException,
 CssResolverException {

  << some code stuff here>>

  com.itextpdf.text.Document document = new com.itextpdf.text.Document();
  PdfWriter writer = PdfWriter.getInstance(document,
   new FileOutputStream(pdfFileNameWithPath));
  document.open();

  HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
  //htmlContext.setLastMarginBottom(100.0f);
  htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
  CSSResolver cssResolver = XMLWorkerHelper.getInstance()
    .getDefaultCssResolver(true);


  Pipeline<?> pipeline = new CssResolverPipeline(cssResolver,
    new HtmlPipeline(htmlContext, new PdfWriterPipeline(document,
      writer)));

  XMLWorker worker = new XMLWorker(pipeline, true);


  XMLParser p = new XMLParser(worker);

  File input = new File(completeHtmlFilePath);
  p.parse(new InputStreamReader(new FileInputStream(input), "UTF-8"));

  document.close();

  return pdfFileNameWithPath;


 }
}
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
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