我有生成pdf文件的代码,我想将其作为电子邮件的附件发送.
我有这个代码:
FileContentResult fileContentResult = File(fileName, "application/pdf", "file.pdf");
Run Code Online (Sandbox Code Playgroud)
我有这个代码通过电子邮件发送附件
Attachment a = new Attachment();
sender.SendMail("a@a.com", "a@a.com", "subject", "Body", a);
Run Code Online (Sandbox Code Playgroud)
如何将FileContentResult转换为Attachment对象?
如何使用itext7在内存流中创建PDF,而不是物理文件?我不知道如何在最新版本中进行操作,有帮助吗?
我尝试了以下代码,但pdfSM未正确填充:
string filePath = "./abc.pdf";
MemoryStream pdfSM = new ByteArrayOutputStream();
PdfDocument doc = new PdfDocument(new PdfReader(filePath), new PdfWriter(pdfSM));
.......
doc.close();
Run Code Online (Sandbox Code Playgroud)
完整的测试代码如下,供您参考,它在filePath进入PdfWriter时有效,但不适用于内存流:
public static readonly String sourceFolder = "../../FormTest/";
public static readonly String destinationFolder = "../../Output/";
static void Main(string[] args)
{
String srcFilePattern = "I-983";
String destPattern = "I-129_2014_";
String src = sourceFolder + srcFilePattern + ".pdf";
String dest = destinationFolder + destPattern + "_flattened.pdf";
MemoryStream returnSM = new MemoryStream();
PdfDocument doc = new PdfDocument(new PdfReader(src), new PdfWriter(returnSM));
PdfAcroForm form …
Run Code Online (Sandbox Code Playgroud)