title: FlyingSaucer renderer.setDocument throws "Stream closed" exception
body: <p>I am having problems with creating a PDF using the simple example found <a href="http://today.java.net/pub/a/today/2007/06/26/generating-pdfs-with-flying-saucer-and-itext.html#an-introduction-to-flying-saucer-and-itext">here</a>. It is my first time trying to use it and I have tried a few things and lots of searching but haven't found a reason why the error is generating. The error originates on the <code>renderer.setDocument(url);</code> line. If anyone has any ideas, suggestions or alternatives it would be greatly appreciated.</p>
  
  <pre><code>package flyingsaucerpdf;
  
  import java.io.*;
  import com.lowagie.text.DocumentException;
  import org.xhtmlrenderer.pdf.ITextRenderer;
  
  public class FirstDoc {
  
      public static void main(String[] args) 
              throws IOException, DocumentException {
          String inputFile = "samples/firstdoc.xhtml";
          String url = new File(inputFile).toURI().toURL().toString();
          String outputFile = "firstdoc.pdf";
          OutputStream os = new FileOutputStream(outputFile);
  
          ITextRenderer renderer = new ITextRenderer();
          renderer.setDocument(url);
          renderer.layout();
          renderer.createPDF(os);
  
          os.close();
      }
  }
  </code></pre>
  
  <p>Console prints out the error below.</p>
  
  <pre><code>ERROR:  'Stream closed'
  org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using TRaX transformer). java.io.IOException: Stream closed
      at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:191)
      at org.xhtmlrenderer.resource.XMLResource.load(XMLResource.java:71)
      at org.xhtmlrenderer.swing.NaiveUserAgent.getXMLResource(NaiveUserAgent.java:211)
      at org.xhtmlrenderer.pdf.ITextRenderer.loadDocument(ITextRenderer.java:134)
      at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:138)
      at com.asiaprice.service.email.template.CompletePdf.createpdf(CompletePdf.java:28)
  </code></pre>