title: XML worker using itext
body: <pre><code>import java.io.FileOutputStream;
  import java.io.StringReader;
  
  import com.itextpdf.text.Document;
  import com.itextpdf.text.PageSize;
  import com.itextpdf.text.pdf.PdfWriter;
  import com.itextpdf.tool.xml.XMLWorkerHelper;
  public class HtmlToPDF2 {
  
        // itextpdf-5.4.1.jar  http://sourceforge.net/projects/itext/files/iText/
        // xmlworker-5.4.1.jar http://sourceforge.net/projects/xmlworker/files/
        public static void main(String[] args ) {
              try {
                Document document = new Document(PageSize.LETTER);
                PdfWriter pdfWriter = PdfWriter.getInstance
                     (document, new FileOutputStream("C:/Users/Jason/Desktop/testpdf.pdf"));
                document.open();
                document.addAuthor("Real Gagnon");
                document.addCreator("Real's HowTo");
                document.addSubject("Thanks for your support");
                document.addCreationDate();
                document.addTitle("Please read this");
  
                XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
  
                String str = "&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;"+
                  "&lt;a href='http://www.rgagnon.com/howto.html'&gt;&lt;b&gt;Real's HowTo&lt;/b&gt;&lt;/a&gt;" +
                  "&lt;h1&gt;Show your support&lt;/h1&gt;" +
                  "&lt;p&gt;It DOES cost a lot to produce this site - in ISP storage and transfer fees, " +
                  "in personal hardware and software costs to set up test environments, and above all," +
                  "the huge amounts of time it takes for one person to design and write the actual content.&lt;/p&gt;" +
                  "&lt;p&gt;If you feel that effort has been useful to you, perhaps you will consider giving something back?&lt;/p&gt;" +
                  "&lt;p&gt;Donate using PayPal® to real@rgagnon.com.&lt;/p&gt;" +
                  "&lt;p&gt;Contributions via PayPal are accepted in any amount&lt;/p&gt;" +
                  "&lt;P&gt;&lt;br/&gt;&lt;table border='1'&gt;&lt;tr&gt;&lt;td&gt;Java HowTo&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;" +
                  "&lt;td style='background-color:red;'&gt;Javascript HowTo&lt;/td&gt;&lt;/tr&gt;" +
                  "&lt;tr&gt;&lt;td&gt;Powerbuilder HowTo&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/p&gt;" +
                  "&lt;/body&gt;&lt;/html&gt;";
                worker.parseXHtml(pdfWriter, document, new StringReader(str));
                document.close();
                System.out.println("Done.");
                }
              catch (Exception e) {
                e.printStackTrace();
              }
            }
  
  }
  </code></pre>
  
  <p>This is a sample code that I found online.When I try executing it I get this error:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoSuchMethodError: com.itextpdf.text.Paragraph.trim()Z
  at com.itextpdf.tool.xml.html.AbstractTagProcessor.currentContentToParagraph(AbstractTagProcessor.java:257)
  at com.itextpdf.tool.xml.html.Header.end(Header.java:93)
  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.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:175)
  at xml.HtmlToPDF2.main(HtmlToPDF2.java:41)
  </code></pre>
  
  <p>I am using itextpdf-5.1.2.jar and xmlworker-5.4.3.jar.Please help</p>