我正在尝试创建 pdf 文件,然后从字节数组添加图像 但我收到了这个错误
正如我的评论中提到的 doc.close 正在关闭你的内存流。所以在关闭之前获取字节。
// Before closing the document, retrieve the bytes
byte[] bytes = ms.ToArray();
doc.Close(); // This will close the MemoryStream `ms`
// Create a new MemoryStream with the bytes of the closed MemoryStream
var resultStream = new MemoryStream(bytes);
// Return a FileStreamResult with the new MemoryStream
return new FileStreamResult(resultStream, "application/pdf");