title: Css styles and images don't apply to pdf generating by Flying Saucer
body: <p>I need to convert some html pages into pdf. After some googling i decide to use Flying Saurcer to perform it. I use this code to do so:</p>
  
  <pre><code>        out = new BufferedOutputStream(new FileOutputStream("/Users/Developer/test.pdf"));
          ITextRenderer renderer = new ITextRenderer();
          renderer.getSharedContext().setNamespaceHandler(new XhtmlNamespaceHandler());
          renderer.getSharedContext().setUserAgentCallback(new CustomUserAgentCallback(renderer.getOutputDevice()));
          renderer.setDocumentFromString(html);
          renderer.layout();
          renderer.createPDF(out);
  </code></pre>
  
  <p>Where CustomUserAgentCallback is:</p>
  
  <pre><code>public class CustomUserAgentCallback extends ITextUserAgent {
  
      public CustomUserAgentCallback(ITextOutputDevice device) {
          super(device);
      }
  /**
   *  {@inheritDoc}
   */
  @Override
  protected InputStream resolveAndOpenStream(String uri) {
      try {
          return new BufferedInputStream(new FileInputStream(resolveURI(uri)));
      } catch (FileNotFoundException e) {
          XRLog.exception(String.format("Cannot resolve file with uri %s", uri));
          return null;
      }
  }
  
  /**
   * {@inheritDoc}
   */
  @Override
  public String resolveURI(String uri) {
      return HttpUtils.getServletAttributes().getRequest().getServletContext().getRealPath("/") + uri;
  }
  }
  </code></pre>
  
  <p>So, resolveURI method forms a valid path to resources (css, images) on server.</p>
  
  <p>But pdf creates without formatting, so styles are ignored as well as img.
  Thanks for attention (and sorry for my English)</p>