title: How to save and load a PDF into memory stream using Spire PDF C#
body: <pre><code>public MemoryStream PdfGeneration(Model model)
  {
      string path = HttpContext.Current.Server.MapPath("test.pdf");
      path = path.Replace("\\api", "");
      FileStream fs = new FileStream(path, FileMode.Create);
      doc.SaveToStream(fs);
      MemoryStream ms = new MemoryStream();
      ms.SetLength(fs.Length);
      fs.Read(ms.GetBuffer(), 0, (int)fs.Length);
      ms.Flush();
      fs.Close();
      return ms;
  }
  </code></pre>
  
  <p>PS: I don't want the file to be read from the disk, it has to be processed in memory. </p>
  
  <p>So here I am using Spire <code>PDF</code> as a generator and I need to save it to memory stream and send as an attachment to mail.</p>