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:我不希望从磁盘读取文件,它必须在内存中处理。
所以在这里我使用 SpirePDF
作为生成器,我需要将其保存到内存流并作为邮件附件发送。