I have an odd issue. I am using iTextSharp 188.8.131.52 in a VS2010 web service. I add a header and footer using the OnEndPage event and then write the document out to a directory. This has worked correctly when testing locally and on the server the service is deployed on. The only time I seem to be getting an issue is when using the service in conjunction with another web app/process, in this case a SharePoint workflow, calling the method.
The error is hit or miss, but I get "Cannot access a closed stream" returned from the service. I have tracked the error down to the page event OnEndPage firing after a document.close is called. If I ignore the exception in the event, I at least get the document generated but of course have no header/footer. I do have other documents with simple text headers working without issue. This header is a table that has a mix of text and an image.
Just an update. I gave up on trying to fix the actual issue and instead went an alternate route. I found for certain that it was just the image causing the issue (I removed the image and had file generating with just a text header for a while without errors). So instead, I have the header text being added using the events and use a stamper on the closed file afterwards to add the image into the header on each page. This is allowing the document to generate without error.