Combine two (or more) PDF's

后端 未结 17 1490
梦毁少年i
梦毁少年i 2020-12-04 07:26

Background: I need to provide a weekly report package for my sales staff. This package contains several (5-10) crystal reports.

Problem:

17条回答
  •  感动是毒
    2020-12-04 07:48

    Combining two byte[] using iTextSharp up to version 5.x:

    internal static MemoryStream mergePdfs(byte[] pdf1, byte[] pdf2)
    {
        MemoryStream outStream = new MemoryStream();
        using (Document document = new Document())
        using (PdfCopy copy = new PdfCopy(document, outStream))
        {
            document.Open();
            copy.AddDocument(new PdfReader(pdf1));
            copy.AddDocument(new PdfReader(pdf2));
        }
        return outStream;
    }
    

    Instead of the byte[]'s it's possible to pass also Stream's

提交回复
热议问题