title: HTML to PDF using iText : How can produce a checkbox
body: <p>I have a simple HTML page, iText is able to produce a PDF from it. It's fine but the checkbox is ignored. What can I do about it ?</p>
  
  <pre><code>import java.io.FileOutputStream;
  import java.io.StringReader;
  
  import com.itextpdf.text.Document;
  import com.itextpdf.text.PageSize;
  import com.itextpdf.text.html.simpleparser.HTMLWorker;
  import com.itextpdf.text.pdf.PdfWriter;
  
  public class HtmlToPDF {
  
    public static void main(String ... args ) {
      try {
        Document document = new Document(PageSize.LETTER);
        PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream("c://temp//testpdf.pdf"));
        document.open();
        String str = "&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;H1&gt;Testing&lt;/H1&gt;&lt;FORM&gt;" + 
                     "check : &lt;INPUT TYPE='checkbox' CHECKED/&gt;&lt;br/&gt;" +
                     "&lt;/FORM&gt;&lt;/BODY&gt;&lt;/HTML&gt;";
  
        htmlWorker.parse(new StringReader(str));
        document.close();
        System.out.println("Done.");
        } 
      catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  </code></pre>
  
  <hr>
  
  <p>I got it working with YAHP ( <a href="http://www.allcolor.org/YaHPConverter/" rel="nofollow">http://www.allcolor.org/YaHPConverter/</a> ). </p>
  
  <pre><code>import java.io.File;
  import java.io.FileOutputStream;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  
  // http://www.allcolor.org/YaHPConverter/
  import org.allcolor.yahp.converter.CYaHPConverter;
  import org.allcolor.yahp.converter.IHtmlToPdfTransformer;
  
  public class HtmlToPdf_yahp {
  
      public  static void main(String ... args ) throws Exception {
          htmlToPdfFile();
      }
  
      public static void htmlToPdfFile() throws Exception {
              CYaHPConverter converter = new CYaHPConverter();
              File fout = new File("c:/temp/x.pdf");
              FileOutputStream out = new FileOutputStream(fout);
              Map properties = new HashMap();
              List headerFooterList = new ArrayList();
  
              String str = "&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;H1&gt;Testing&lt;/H1&gt;&lt;FORM&gt;" +
                           "check : &lt;INPUT TYPE='checkbox' checked=checked/&gt;&lt;br/&gt;"   +
                           "&lt;/FORM&gt;&lt;/BODY&gt;&lt;/HTML&gt;"; 
  
              properties.put(IHtmlToPdfTransformer.PDF_RENDERER_CLASS,
                      IHtmlToPdfTransformer.FLYINGSAUCER_PDF_RENDERER);
              //properties.put(IHtmlToPdfTransformer.FOP_TTF_FONT_PATH, fontPath);
              converter.convertToPdf(str,
                  IHtmlToPdfTransformer.A4P, headerFooterList, "file://c:/temp/", out,
                  properties);
              out.flush();
              out.close();
      }
  }
  </code></pre>