Hi,
Hi John,
Thanks for your inquiry. It seems the API is looking for merged files (nextPdf object) at the time of saving the final document (pdfDoc) and throwing the exception. I have logged a ticket PDFNEWNET-37879 for further investigation and resolution. We will keep you updated about the issue resolution progress. Meanwhile, you can use the following code snippet without the second using block.
using (var stream = new MemoryStream())
{
// Start by opening the first PDF
using (var pdfDoc = new Document(pdfFiles[0]))
{
var nextPdf = new Document();
// Starting with the second, concatenate all the rest
for (int i = 1; i < pdfFiles.Count; i++)
{
nextPdf = new Document(pdfFiles[i]);
pdfDoc.Pages.Add(nextPdf.Pages);
pdfDoc.Save(stream); // Error: Cannot access a closed Stream.
nextPdf.Dispose();
}
return new FileContentResult(stream.ToArray(), "application/pdf");
}
}
We are sorry for the inconvenience caused.
Best Regards,
Thanks, but doesn’t this cause the problem I was trying to prevent (by utilizing the using construct)?
Hi John,