0

I am able to save single attachments using below code

var mimePart = (attachment as MimePart);

using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
    mimePart.ContentObject.DecodeTo(fileStream);
}

Here each attachment is saved as separate file, But I want to save multiple attachments as single pdf file I am not able to find any method for merging in MimePart.

vaibhav shah
  • 4,939
  • 19
  • 58
  • 96

1 Answers1

1

I recently had this exact requirement. To merge Pdf-files I used PdfSharp:

using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;

public static void MergePDFS(string target, params string[] pdfs)
{
   using (var targetDoc = new PdfDocument())
   {
       foreach (var pdf in pdfs)
       {
            using (var pdfDoc = PdfReader.Open(pdf, PdfDocumentOpenMode.Import))
            {
                for (var i = 0; i < pdfDoc.PageCount; i++)
                    targetDoc.AddPage(pdfDoc.Pages[i]);
            }
        }
            targetDoc.Save(target);
        }
    }
}

Here is a related question

J. S. Garcia
  • 366
  • 1
  • 9