Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

Cannot access a closed Stream Concatenating PDFs

$
0
0
Hi,

I'm getting a "Cannot access a closed Stream." in the code below when I try to save to a stream. I am simply trying to concatenate pdfs in a loop.

I am using version 9.8.0.0

Any help is appreciated. 
Thanks.

using (var stream = new MemoryStream())
{
    // Start by opening first pdf
    using (var pdfDoc = new Document(pdfFiles[0]))
    {
        // Starting with second, concat all the rest
        for (int i = 1; i < pdfFiles.Count; i++)
        {
            using (var nextPdf = new Document(pdfFiles[i]))
            {
                pdfDoc.Pages.Add(nextPdf.Pages);
            }
        }
        pdfDoc.Save(stream); // Error: Cannot access a closed Stream. 
    }
    return new FileContentResult(stream.ToArray(), "application/pdf");
}

Viewing all articles
Browse latest Browse all 3131

Trending Articles