'attachmentFilePath' is a physically existing file on the file system.
using (var pdfDoc = new PDFDoc(pdfFile, pdfFile.Length)) {
... Now is there a more elegant / in-memory way to do this? I have all the attachments there only in memory anyway and would rather not write to the filesystem but the .AddFileAttachment(..) method of the PDFDoc class requires a FileSpec, which again seems to only take strings pointing to existing files.
Yup, you can create a FileSpec from a memory buffer as follows:
FileSpec CreateMyFileSpec(PDFDoc doc, string path, bye[] data) {
Obj fs = doc.CreateIndirectDict();
fs.PutName("Type", "Filespec");
fs.PutString("F", path);
fs.PutText("UF", path);
fs.PutDict("EF").Put("F", doc.CreateIndirectStream(data));
return new FileSpec(fs);
}
Then add the file stream as before:
pdfDoc.AddFileAttachment("iRMA Creation .xml File", CreateMyFileSpec(pdfDoc, "foo", data) );