title: iText 7 - HTML to PDF write to MemoryStream instead of file
body: <p>I'm using iText 7, specifically the <code>HtmlConverter.ConvertToDocument</code> method, to convert HTML to PDF.  The problem is, I would really rather not create a PDF file on my server, I'd rather do everything in memory and just send it to the users browser so they can download it.</p>
  
  <p>Could anyone show me an example of how to use this library but instead of writing to file write to a MemoryStream so I can send it directly to the browser?</p>
  
  <p>I've been looking for examples and all I can seem to find are those which refer to file output.</p>
  
  <p>I've tried the following, but keep getting an error about cannot access a closed memory stream.</p>
  
  <pre><code>public FileStreamResult pdf() {
      using (var workStream = new MemoryStream())
      using (var pdfWriter = new PdfWriter(workStream)) {
          pdfWriter.SetCloseStream(false);
          using (var document = HtmlConverter.ConvertToDocument(html, pdfWriter)) {
              //Returns the written-to MemoryStream containing the PDF.   
              byte[] byteInfo = workStream.ToArray();
              workStream.Write(byteInfo, 0, byteInfo.Length);
              workStream.Position = 0;
  
              return new FileStreamResult(workStream, "application/pdf");
          }
          //return new FileStreamResult(workStream, "application/pdf");
      }
  }
  </code></pre>