0

Here is my code, I am getting below runtime error

"Exception in thread "main" java.lang.NoClassDefFoundError: com/itextpdf/kernel/counter/event/IMetaInfo".

/** The HTML-string that we are going to convert to PDF. */
public static final String HTML = "<h1>Test</h1><p>Hello World</p>";
/** The target folder for the result. */
public static final String TARGET = "target/results/ch01/";
/** The path to the resulting PDF file. */
public static final String DEST = String.format("%stest-1.pdf", TARGET);

/**
 * The main method of this example.
 *
 * @param args no arguments are needed to run this example.
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void main(String[] args) throws IOException {

    File file = new File(TARGET);
    file.mkdirs();
    new HelloWorld().createPdf(HTML, DEST);
}

/**
 * Creates the PDF file.
 *
 * @param html the HTML as a String value
 * @param dest the path of the resulting PDF
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void createPdf(String html, String dest) throws IOException {
    HtmlConverter.convertToPdf(html, new FileOutputStream(dest));
}
Shiva
  • 1,962
  • 2
  • 13
  • 31
  • How are you running the program? The error is suggesting that the class is not available at runtime but present at compile time – Shiva Nov 15 '18 at 11:20
  • Seems like the class `com.itextpdf.kernel.counter.event.IMetaInfo` is not on the clsspath. Could you supply the stack trace ? That would help finding the cause of the problem. – tom1299 Nov 15 '18 at 11:21
  • @secretsuperstar exactly this is something that is happening. – Sonam Ramchand Nov 15 '18 at 11:32
  • @tom1299 when i try to import com.itextpdf.kernel.counter.event.IMetaInfo, I am getting com.itextpdf.kernel.counter cannot be resolved. – Sonam Ramchand Nov 15 '18 at 11:33
  • 1
    Is the `kernel` jar present in your classpath? – Shiva Nov 15 '18 at 11:34
  • Please check @secretsuperstar last comment. It really seems like your classpath for both compilation & running is not set up correctly. – tom1299 Nov 15 '18 at 12:21
  • Which iText artifact versions do you have on your class path? Probably your pdfHtml version is to young for the iText base classes... – mkl Nov 15 '18 at 17:50

0 Answers0