Returning iTextSharp PDF as memorystream causes StreamNotSupported

The problem arises because the memory stream gets implicitly closed when the PdfStamper is closed. To prevent this add

pdfStamper.Writer.CloseStream = false;

before

pdfStamper.Close();

This instructs the stamper not to close the stream.

Leave a Comment