itext7 merge pdfs from list byte array code example
Example: c# itext 7 PdfDocument from byte array
using (MemoryStream ms = new MemoryStream())
using (PdfDocument pdf = new PdfDocument(new PdfWriter(ms).SetSmartMode(true)))
{
using (MemoryStream memoryStream = new MemoryStream(pdf1.DocumentBytes))
{
using (PdfReader reader = new PdfReader(memoryStream))
{
PdfDocument srcDoc = new PdfDocument(reader);
srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf);
}
}
using (MemoryStream memoryStream = new MemoryStream(pdf2.DocumentBytes))
{
using (PdfReader reader = new PdfReader(memoryStream))
{
PdfDocument srcDoc = new PdfDocument(reader);
srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf);
}
}
pdf.Close();
return ms.ToArray();
}