title: HTML to PDF conversion using iText
body: <p>I'm trying to convert an HTMLl file to PDF.  For that I'm using <a href="http://itextpdf.com/" rel="nofollow">iText</a>.  If the HTML has some image in its body, iText fails to put that image in the PDF and it throws the following exception.  </p>
  
  <blockquote>
    <p><code>ExceptionConverter: java.io.FileNotFoundException: D:\cid:870001313@01022011-2B8B (The system cannot find the file specified).</code></p>
  </blockquote>
  
  <p>If the HTML has some image in its body, is it possible to read that image and make it as attachment to that PDF file?  Here is my source code (Truncate.java):</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.DataInputStream;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.FileReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.util.ArrayList;
  
  import com.lowagie.text.Document;
  import com.lowagie.text.DocumentException;
  import com.lowagie.text.Element;
  import com.lowagie.text.Paragraph;
  import com.lowagie.text.html.simpleparser.HTMLWorker;
  import com.lowagie.text.pdf.PdfWriter;
  
  public class Truncate {
      public static void main(String[] args) throws DocumentException {
          // TODO Auto-generated method stub
          FileReader fr = null;
          Document document = new Document();
          document.open();
          PdfWriter writer = null;
          try {
              String file_name = "C:\\Documentum\\Viewed\\911.htm";
              fr = new FileReader(file_name);
              PdfWriter.getInstance(document, System.out);
              writer = PdfWriter.getInstance(document, new FileOutputStream(
                      "C:\\Documentum\\Viewed\\RH\\RH.pdf"));
              document.add(new Paragraph("RH Mail"));
              ArrayList htmlContentList = HTMLWorker.parseToList(fr, null);
  
              //fetch the html content line by line
              for (int htmlDataCntr = 0; htmlDataCntr &lt; htmlContentList.size(); htmlDataCntr++) {
                  Element htmlDataElement = (Element) htmlContentList
                          .get(htmlDataCntr);
                  document.add(htmlDataElement);
              }
              fr.close();
              document.close();
  
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          }
          catch (IOException e) {
              e.printStackTrace();
          }
          catch(Exception e){
              System.out.println(e);
          }
      }
  }
  </code></pre>