title: html to pdf generation using itext in java
body: <p><strong>Description</strong>:<br>
  <strong><em>ouput</em></strong>: <code>pdf file</code><br>
  <strong><em>input</em></strong> : <code>index.css</code>, <code>bootstrap.min.css</code>, <code>index.html</code></p>
  
  <p><strong>Problem</strong>: if i use index.css file without bootsrap its working fine, but when i use boot strap its throw exception.</p>
  
  <p><strong>CODE is here:</strong></p>
  
  <pre><code>package test.test1;
  
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  
  import org.apache.commons.codec.Charsets;
  
  import com.google.common.io.CharStreams;
  import com.itextpdf.text.Document;
  import com.itextpdf.text.DocumentException;
  import com.itextpdf.text.PageSize;
  import com.itextpdf.text.pdf.PdfWriter;
  import com.itextpdf.tool.xml.Pipeline;
  import com.itextpdf.tool.xml.XMLWorker;
  import com.itextpdf.tool.xml.XMLWorkerHelper;
  import com.itextpdf.tool.xml.css.CssFile;
  import com.itextpdf.tool.xml.css.StyleAttrCSSResolver;
  import com.itextpdf.tool.xml.html.Tags;
  import com.itextpdf.tool.xml.parser.XMLParser;
  import com.itextpdf.tool.xml.pipeline.css.CSSResolver;
  import com.itextpdf.tool.xml.pipeline.css.CssResolverPipeline;
  import com.itextpdf.tool.xml.pipeline.end.PdfWriterPipeline;
  import com.itextpdf.tool.xml.pipeline.html.HtmlPipeline;
  import com.itextpdf.tool.xml.pipeline.html.HtmlPipelineContext;
  
  public class Table {
  
  
  
      File oFile = new File("c:\\test\\1.pdf");
      Document document = new Document(PageSize.A4, 0, 0, 0, 0);
      PdfWriter writer =null;
  
      public Table() throws IOException, DocumentException {
          oFile.createNewFile();
          writer=PdfWriter.getInstance(document,new FileOutputStream(oFile));
  
  
          InputStream htmlpathtest = Thread.currentThread()
                  .getContextClassLoader()
                  .getResourceAsStream("index.html");
          String htmlstring = CharStreams.toString(new InputStreamReader(htmlpathtest, Charsets.UTF_8));
  
          InputStream is = new ByteArrayInputStream(htmlstring.getBytes());
  
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
  
          PdfWriter writer = PdfWriter.getInstance(document, baos);
  
          writer.setInitialLeading(12.5f);
  
          document.open();
  
          HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
  
          htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
  
          // CSS
          CSSResolver cssResolver = new StyleAttrCSSResolver();
          InputStream csspathtest = Thread.currentThread()
                  .getContextClassLoader()
                  .getResourceAsStream("css\\index.css");
  
          InputStream csspathtest1 = Thread.currentThread()
                  .getContextClassLoader()
                  .getResourceAsStream("css\\bootstrap.min.css");
  
          CssFile cssfiletest = XMLWorkerHelper.getCSS(csspathtest);
          cssResolver.addCss(cssfiletest);
          cssResolver.addCss(XMLWorkerHelper.getCSS(csspathtest1));
  
  
          Pipeline&lt;?&gt; pipeline = new CssResolverPipeline(cssResolver,
                  new HtmlPipeline(htmlContext, new PdfWriterPipeline(
                          document, writer)));
  
          XMLWorker worker = new XMLWorker(pipeline, true);
          XMLParser p = new XMLParser(worker);
          p.parse(is);
         document.close();
      }
          public static void main(String[] args) throws IOException, DocumentException {  new Table();}
  }
  </code></pre>
  
  <p><strong>Exception:</strong></p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.NumberFormatException: For input
    string: "100%"    at
    sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1222)
      at java.lang.Float.parseFloat(Float.java:422)   at
    com.itextpdf.tool.xml.css.FontSizeTranslator.getFontSize(FontSizeTranslator.java:186)
      at
    com.itextpdf.tool.xml.css.FontSizeTranslator.translateFontSize(FontSizeTranslator.java:165)
      at
    com.itextpdf.tool.xml.html.AbstractTagProcessor.startElement(AbstractTagProcessor.java:120)
      at
    com.itextpdf.tool.xml.pipeline.html.HtmlPipeline.open(HtmlPipeline.java:105)
      at com.itextpdf.tool.xml.XMLWorker.startElement(XMLWorker.java:103)
      at
    com.itextpdf.tool.xml.parser.XMLParser.startElement(XMLParser.java:372)
      at
    com.itextpdf.tool.xml.parser.state.TagEncounteredState.process(TagEncounteredState.java:104)
      at
    com.itextpdf.tool.xml.parser.XMLParser.parseWithReader(XMLParser.java:237)
      at com.itextpdf.tool.xml.parser.XMLParser.parse(XMLParser.java:215)
      at com.itextpdf.tool.xml.parser.XMLParser.parse(XMLParser.java:188)
      at test.test1.Table.(Table.java:95)   at
    test.test1.Table.main(Table.java:104)</p>
  </blockquote>