Background: I need to provide a weekly report package for my sales staff. This package contains several (5-10) crystal reports.
Problem:
This is something that I figured out, and wanted to share with you.
Here you can join multiple Pdfs in one (following the input list order)
public static byte[] MergePdf(List pdfs)
{
List lstDocuments = new List();
foreach (var pdf in pdfs)
{
lstDocuments.Add(PdfReader.Open(new MemoryStream(pdf), PdfDocumentOpenMode.Import));
}
using (PdfSharp.Pdf.PdfDocument outPdf = new PdfSharp.Pdf.PdfDocument())
{
for(int i = 1; i<= lstDocuments.Count; i++)
{
foreach(PdfSharp.Pdf.PdfPage page in lstDocuments[i-1].Pages)
{
outPdf.AddPage(page);
}
}
MemoryStream stream = new MemoryStream();
outPdf.Save(stream, false);
byte[] bytes = stream.ToArray();
return bytes;
}
}