0
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;
}

PS: I don't want the file to be read from the disk, it has to be processed in memory.

So here I am using Spire PDF as a generator and I need to save it to memory stream and send as an attachment to mail.

Peter Hall
  • 53,120
  • 14
  • 139
  • 204
surya
  • 1
  • 1
  • 1

1 Answers1

2

To load file from stream, you can use LoadFromStream method

PdfDocument doc = new PdfDocument();
doc.LoadFromStream(Stream stream);
Kumar
  • 17
  • 1