title: Generate Pdf from Html string with image and css for android using itext
body: <p>I am using itext-5.3.4.jar and xmlworker-1.2.1.jar library for generate pdf from html string , html contains image logo and inline css.</p>
  
  <p>My html file and image is in Asset folder , using this library my pdf generating successfully but there is no image display and no css style randering. anyone has a suggestion what should i do to fix this issue, if any other library or any other option for generate pdf from html will be helpful.</p>
  
  <p>I am using these function for generate pdf:</p>
  
  <pre><code>    public static void generatePdfFromHtlm(String fileName, String htmlString){
  
  
      try {
          File mediaStorageDir = new File(Environment.getExternalStorageDirectory(), AppConfig.getContext().getPackageName() + "/" + "Pdf");
  
          if (!mediaStorageDir.exists()) {
              mediaStorageDir.mkdirs();
          }
  
          File fileWithinMyDir = new File(mediaStorageDir, fileName);
  
          FontFactory.registerDirectories();
          Document document = new Document(PageSize.A4);
          PdfWriter writer = PdfWriter.getInstance(document,
                  new FileOutputStream(fileWithinMyDir));
          document.open();
          HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
          htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
          htmlContext.setImageProvider(new AbstractImageProvider() {
              public String getImageRootPath() {
  
                  Uri uri = Uri.parse("file:///android_asset/");
  
                  String newPath = uri.toString();
  
                  return newPath;
              }
          });
  
  
          CSSResolver cssResolver =
                  XMLWorkerHelper.getInstance().getDefaultCssResolver(false);
          /*Pipeline&lt;?&gt; pipeline =
                  new CssResolverPipeline(cssResolver,
                          new HtmlPipeline(htmlContext,
                                  new PdfWriterPipeline(document, writer)));*/
  
          // Pipelines
          PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);
          HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
          CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);
  
          XMLWorker worker = new XMLWorker(css, true);
  
          XMLParser p = new XMLParser(worker);
          InputStream is = new ByteArrayInputStream(htmlString.getBytes());
          p.parse(is);
  
          document.close();
  
  
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p><strong>my html file is</strong> </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;!--[if IE 8]&gt; &lt;html lang="en" class="ie8"&gt; &lt;![endif]--&gt;
  &lt;!--[if IE 9]&gt; &lt;html lang="en" class="ie9"&gt; &lt;![endif]--&gt;
  &lt;!--[if !IE]&gt;&lt;!--&gt;
  &lt;html lang="en"&gt; &lt;!--&lt;![endif]--&gt;
  
  &lt;!-- BEGIN HEAD --&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8" /&gt;
    
    &lt;title&gt;WeighInsheet&lt;/title&gt; 
    
    
    &lt;style type="text/css"&gt;
    
    body { font-family:Arial; }
        .Wrapper { border:1px solid #cccccc; height:auto; margin:0px 65px;}
        .header { height:105px; margin:5px; float:left;}
        .logo { width:100px; height:100px; float:left; }
    .heading { width:600px;}
    h2{ margin:40px 0px 0px 0px;font-size: 22px; font-weight:bold;}
    h3{ margin:0px; font-weight:normal;font-size: 16px;}
    table { border-collapse: collapse; border-spacing: 0;  width:100%; }
    table td { font-family: arial; font-size: 14px; padding: 10px 5px; border: 1px solid #ddd; }  
    table th { background-color:#000000; color:#ffffff; font-family: arial; font-size: 16px; font-weight: bold;
               border: 1px solid #ddd; }  
    
    &lt;/style&gt;
  
  
  &lt;/head&gt;
  
  &lt;!-- END HEAD --&gt;
  
  &lt;!-- BEGIN BODY --&gt;
  
  &lt;body&gt;  
    
  &lt;div class="Wrapper"&gt;
  
  &lt;div class="header"&gt;
  
  &lt;div class="logo"&gt;&lt;img src="logo.jpg" class="logo"/&gt;&lt;/div&gt;
  
  &lt;div class="heading" align="center"&gt;
  &lt;h2&gt;Description&lt;/h2&gt;
  &lt;h3&gt;Title Meta&lt;/h3&gt;
  &lt;/div&gt;
  
  &lt;/div&gt;
  &lt;table&gt;
  
  &lt;thead&gt;
   ##CHANGEHEADER##
  &lt;/thead&gt;
  
  &lt;tbody&gt;
    ##CHANGEBODY##
  &lt;/tbody&gt;
  
  &lt;/table&gt;
  
  &lt;/div&gt;  
  
  &lt;/body&gt;
  
  &lt;!-- END BODY --&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>My Image file <strong>"logo.jpg"</strong> is in asset folder .</p>