title: java.lang.noClassDefFoundError: com/itextpdf/text/element on a Java Applet
body: <p>I'm trying to code a Word-To-PDF Converter and build the Java Code into a HTML Website in form of a Java Applet. </p>
  
  <p>I used the Java Code from <a href="http://java.worldbestlearningcenter.com/2013/07/word-to-pdf-converter.html" rel="nofollow noreferrer">http://java.worldbestlearningcenter.com/2013/07/word-to-pdf-converter.html</a>. The code itself seems to work perfectly fine, when I run the program in Eclipse, I can indeed convert a word document to a PDF. Now I'd like to add that code to my HTML file and make it work.</p>
  
  <p>To do so, I made my class herit from JApplet and wrote the method paint().
  The code I have by now looks like the snippet below:</p>
  
  
  
  <pre class="lang-java prettyprint-override"><code>import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.util.Iterator;
  import java.util.List;
  import javax.swing.JFileChooser;
  import javax.swing.filechooser.FileNameExtensionFilter;
  import org.apache.poi.xwpf.usermodel.XWPFDocument;
  import org.apache.poi.xwpf.usermodel.XWPFParagraph;
  import org.apache.poi.xwpf.usermodel.XWPFPicture;
  import org.apache.poi.xwpf.usermodel.XWPFPictureData;
  import org.apache.poi.xwpf.usermodel.XWPFRun;
  import com.itextpdf.text.Chunk;
  import com.itextpdf.text.BaseColor;
  import com.itextpdf.text.Document;
  import com.itextpdf.text.Font;
  import com.itextpdf.text.FontFactory;
  import com.itextpdf.text.Image;
  import com.itextpdf.text.pdf.PdfWriter;
  import com.itextpdf.text.PageSize;
  import java.applet.*;
  import java.awt.*;
  
  public class ConverterApplet extends Applet {
      private static final long serialVersionUID = 1L;
  
      public void paint(Graphics g) {
          g.drawString("Hello", 60, 40);
          selectFiles();
      }
  
      public static void selectFiles(){
          JFileChooser chooser = new JFileChooser();
          FileNameExtensionFilter filter = new FileNameExtensionFilter("Microsoft Word 2007+", "docx");
          chooser.setFileFilter(filter);
          chooser.setMultiSelectionEnabled(true);
          int returnVal = chooser.showOpenDialog(null);
          if(returnVal == JFileChooser.APPROVE_OPTION) {
              File[] Files=chooser.getSelectedFiles();
              System.out.println("Konvertierung gestartet ...");
              for( int i=0;i&lt;Files.length;i++){     
                  String wordfile=Files[i].toString();            
                  convertWordToPdf(wordfile,wordfile.substring(0,wordfile.indexOf('.'))+".pdf");
              }
  
              System.out.println("Konvertierung abgeschlossen!");
          }
      }
  
      public static void convertWordToPdf(String src, String desc){
          try {
              //create file inputstream object to read data from file 
              FileInputStream fs=new FileInputStream(src);
              //create document object to wrap the file inputstream object
              XWPFDocument doc=new XWPFDocument(fs); 
              //72 units=1 inch
              Document pdfdoc=new Document(PageSize.A4,72,72,72,72);
              //create a pdf writer object to write text to mypdf.pdf file
              PdfWriter pwriter=PdfWriter.getInstance(pdfdoc, new FileOutputStream(desc));
              //specify the vertical space between the lines of text
              pwriter.setInitialLeading(20);
              //get all paragraphs from word docx
              List&lt;XWPFParagraph&gt; plist=doc.getParagraphs();
  
              //open pdf document for writing
              pdfdoc.open();
              for (int i = 0; i &lt; plist.size(); i++) {
                  //read through the list of paragraphs
                  XWPFParagraph pa = plist.get(i);
                  //get all run objects from each paragraph
                  List&lt;XWPFRun&gt; runs = pa.getRuns();
                  //read through the run objects
                  for (int j = 0; j &lt; runs.size(); j++) {       
                      XWPFRun run=runs.get(j);
                      //get pictures from the run and add them to the pdf document
                      List&lt;XWPFPicture&gt; piclist=run.getEmbeddedPictures();
                      //traverse through the list and write each image to a file
                      Iterator&lt;XWPFPicture&gt; iterator=piclist.iterator();
                      while(iterator.hasNext()){
                          XWPFPicture pic=iterator.next();
                          XWPFPictureData picdata=pic.getPictureData();
                          byte[] bytepic=picdata.getData(); 
                          Image imag=Image.getInstance(bytepic);
                          pdfdoc.add(imag);
  
                      }
                      //get color code
                      int color=getCode(run.getColor());
                      //construct font object
                      Font f=null;
                      if(run.isBold() &amp;&amp; run.isItalic())
                          f=FontFactory.getFont(FontFactory.TIMES_ROMAN,run.getFontSize(),Font.BOLDITALIC, new BaseColor(color));
                      else if(run.isBold())
                          f=FontFactory.getFont(FontFactory.TIMES_ROMAN,run.getFontSize(),Font.BOLD, new BaseColor(color));
                      else if(run.isItalic())
                          f=FontFactory.getFont(FontFactory.TIMES_ROMAN,run.getFontSize(),Font.ITALIC, new BaseColor(color));
                      else if(run.isStrike())
                          f=FontFactory.getFont(FontFactory.TIMES_ROMAN,run.getFontSize(),Font.STRIKETHRU, new BaseColor(color));
                      else
                          f=FontFactory.getFont(FontFactory.TIMES_ROMAN,run.getFontSize(),Font.NORMAL, new BaseColor(color));
                      //construct unicode string
                      String text=run.getText(-1);
                      byte[] bs;
                      if (text!=null){
                          bs=text.getBytes();
                          String str=new String(bs,"UTF-8");
                          //add string to the pdf document
                          Chunk chObj1=new Chunk(str,f);
                          pdfdoc.add(chObj1);
                      }      
  
                  }
                  //output new line
                  pdfdoc.add(new Chunk(Chunk.NEWLINE));
              }
              //close pdf document  
              pdfdoc.close();
          } catch(Exception e){
              e.printStackTrace();
          }
      } 
  
      public static int getCode(String code){
          int colorCode;
          if(code!=null)
              colorCode=Long.decode("0x"+code).intValue();
          else
              colorCode=Long.decode("0x000000").intValue();
          return colorCode;
      }
  }
  </code></pre>
  
  <p>I created a HTML document with the following code:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;DOCTYPE! html&gt;
  &lt;html lang="DE-CH"&gt;
      &lt;head&gt;
          &lt;title&gt;Testseite&lt;/title&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;h1&gt;Titel&lt;/h1&gt;
  
          &lt;object type="application/x-java-applet" width="800" height="600"&gt;
              &lt;param name="code" value="ConverterApplet" /&gt;
              &lt;param name="archive" value="ConverterApplet.jar" /&gt;
              Applet failed to run.  No Java plug-in was found.
          &lt;/object&gt;
  
      &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>When trying to open that HTML page in Internet Explorer (Chrome and Firefox seem not to work and even IE needs a special permission), I get the error "java.lang.noClassDefFoundError: com/itextpdf/text/element".</p>
  
  <p><a href="https://i.stack.imgur.com/6kXBN.jpg" rel="nofollow noreferrer"></a></p>
  
  <p>What I can also tell already:</p>
  
  <ul>
  <li>I only have one JAR File for itextpdf. Its the version 5.1.0, because 2.1.7 does not include all packages that specific code needs. There is no other JAR File similar to itextpdf.</li>
  <li>I have all JAR Files in the WEB-INF/lib folder within the project's folder</li>
  <li>All JAR Files inside the lib folder are also in CLASSPATH.</li>
  <li>I have an updated version of my code exported as "ConverterApplet.jar", also have that file in the project's root folder and also in CLASSPATH.</li>
  <li>I tried the browsers Chrome, Firefox, Opera, Edge and Internet Explorer. Only the last one even gave me the possibility to see the (not working) applet, all others said "no plugin found".</li>
  </ul>
  
  <p>I couldn't find any other help on the web apart the bullet points I listed above. I'm really clueless what else could be the problem to get such an error, especially because the Java code itself works inside Eclipse, but not outside. Any help would really be apperciated.</p>
  
  <p>== EDIT ==
  .classpath File:</p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;classpath&gt;
      &lt;classpathentry kind="src" path="src"/&gt;
      &lt;classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/&gt;
      &lt;classpathentry kind="lib" path="C:/Users/silve/Documents/Eclipse_Launch/Converter/ConverterApplet.jar"/&gt;
      &lt;classpathentry kind="lib" path="C:/Users/silve/Documents/Eclipse_Launch/Converter/dom4j-1.6.1.jar"/&gt;
      &lt;classpathentry kind="lib" path="C:/Users/silve/Documents/Eclipse_Launch/Converter/openxml4j-1.0-beta.jar"/&gt;
      &lt;classpathentry kind="lib" path="C:/Users/silve/Documents/Eclipse_Launch/Converter/poi-3.9.jar"/&gt;
      &lt;classpathentry kind="lib" path="C:/Users/silve/Documents/Eclipse_Launch/Converter/poi-ooxml-3.8.jar"/&gt;
      &lt;classpathentry kind="lib" path="C:/Users/silve/Documents/Eclipse_Launch/Converter/poi-ooxml-schemas-3.9.jar"/&gt;
      &lt;classpathentry kind="lib" path="C:/Users/silve/Documents/Eclipse_Launch/Converter/xmlbeans-2.5.0.jar"/&gt;
      &lt;classpathentry kind="lib" path="C:/Users/silve/Documents/Eclipse_Launch/Converter/itextpdf-5.5.12.jar"/&gt;
      &lt;classpathentry kind="output" path="bin"/&gt;
  &lt;/classpath&gt;
  </code></pre>
  
  <p>New HTML File:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;DOCTYPE! html&gt;
  &lt;html lang="DE-CH"&gt;
      &lt;head&gt;
          &lt;title&gt;Testseite&lt;/title&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;h1&gt;Titel&lt;/h1&gt;
  
          &lt;object type="application/x-java-applet" width="800" height="600"&gt;
              &lt;param name="code" value="ConverterApplet" /&gt;
              &lt;param name="archive" value="~/ConverterApplet.jar" /&gt;
              &lt;param name="dom_archive" value="~/dom4j-1.6.1.jar" /&gt;
              &lt;param name="itext_archive" value="~/itextpdf-5.5.12.jar" /&gt;
              &lt;param name="openxml_archive" value="~/openxml4j-1.0-beta.jar" /&gt;
              &lt;param name="poi_archive" value="~/poi-3.9.jar" /&gt;
              &lt;param name="ooxml_archive" value="~/poi-ooxml-3.8.jar" /&gt;
              &lt;param name="schemas_archive" value="~/poi-ooxml-schemas-3.9.jar" /&gt;
              &lt;param name="mxmlbeans_archive" value="~/xmlbeans-2.5.0" /&gt;
  
              Applet failed to run.  No Java plug-in was found.
          &lt;/object&gt;
  
      &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>Right now I'm getting the error "NoClassFound" by IE.</p>