0

I am testing ItexPDF with XHTMLRendered to parse a web to a pdf and got this error

java.lang.NoClassDefFoundError: com/lowagie/text/pdf/PdfTemplate
org.docx4j.org.xhtmlrenderer.pdf.ITextRenderer.<init>(ITextRenderer.java:109)
org.docx4j.org.xhtmlrenderer.pdf.ITextRenderer.<init>(ITextRenderer.java:103)

I am using iTextPDF 5.5.7 and xhtmlrendered.1.0. My code:

String File_To_Convert = "http://localhost:8080/index.php";   
 String url = new File(File_To_Convert).toURI().toURL().toString();
 System.out.println(""+url);
 String HTML_TO_PDF = "ConvertedFile.pdf";
OutputStream os = new FileOutputStream(HTML_TO_PDF); 
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);      
renderer.layout();
renderer.createPDF(os);        
os.close();`
Alexev
  • 157
  • 2
  • 19
  • Rebuild your project, it seems `PdfTemplate` is not visible to itext. – px5x2 Nov 04 '15 at 12:44
  • Ive done it and failed:`class file for com.lowagie.text.DocumentException not found` – Alexev Nov 04 '15 at 12:50
  • add the itexjar to the class path. – Sasi Kathimanda Nov 04 '15 at 12:51
  • The iText-5.5.7.jar is in my classpath so are the extra jars in the version – Alexev Nov 04 '15 at 12:57
  • You include the current iText (5.5.7) but your `xhtmlrendered` seems to require an ancient iText version (< 5) – mkl Nov 04 '15 at 13:10
  • O.o I didnt know that, so I have to downgrade to earlier versions of Itext then. thank you very muich, Ill try that – Alexev Nov 04 '15 at 13:14
  • @Alexev You are using Flying Saucer, an unsupported product that *uses* an obsolete, unsupported version of iText. Flying Saucer isn't created by iText Group, nor endorsed by iText Group. Basically: if you see my name in the class path, you know that you're using ancient, unsupported software. – Bruno Lowagie Nov 04 '15 at 15:22
  • @BrunoLowagie Thanks for your answer Bruno, I tried that one because was your recomendation at the book when the question was "parsing HTML to PDF" :( – Alexev Nov 05 '15 at 12:32
  • You must have a mighty old book (2010) where I say *Usually you’ll get advice to use another product; for instance, xhtmlrenderer, aka Flying Saucer—a project that is built on top of iText.* That isn't a recommendation. That's what I noticed when reading answers back in 2009. When that book was written, XML Worker didn't exist yet. – Bruno Lowagie Nov 05 '15 at 12:38
  • o.O ok, I will be tryng XMLWorker then :) and find myself newer documentations :) All I have so far is the SO Q&A and the Itext in action 2dn edition 2011 – Alexev Nov 05 '15 at 13:27

0 Answers0