Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# itext 7 PdfDocument from byte array

using (MemoryStream ms = new MemoryStream())
using (PdfDocument pdf = new PdfDocument(new PdfWriter(ms).SetSmartMode(true)))
{
    // Create reader from bytes
    using (MemoryStream memoryStream = new MemoryStream(pdf1.DocumentBytes))
    {
        // Create reader from bytes
        using (PdfReader reader = new PdfReader(memoryStream))
        {
            PdfDocument srcDoc = new PdfDocument(reader);
            srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf);
        }
    }

    // Create reader from bytes
    using (MemoryStream memoryStream = new MemoryStream(pdf2.DocumentBytes))
    {
        // Create reader from bytes
        using (PdfReader reader = new PdfReader(memoryStream))
        {
            PdfDocument srcDoc = new PdfDocument(reader);
            srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf);
        }
    }

    // Close pdf
    pdf.Close();

    // Return array
    return ms.ToArray();
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #itext #PdfDocument #byte #array
ADD COMMENT
Topic
Name
1+1 =