When itextsharp was used, there was a small problem. otherwise, this is indeed a very convenient and perfect component, but some domestic online solutions are copied and searched. They are all the same, which is quite disgusting. when using itextsharp, if you need to write the generated PDF content to stream, note that stream will be closed by the itextsharp object. otherwise, an error "can not access with closed stream" is reported when streaming operations are performed."
- Using writer. getinstance (document, stream). closestream =False;
Another problem is that when itextsharp writes the stream to memorystream, if the stream is used as an attachment, the stream pointer needs to be moved to the starting place, otherwise, the attachment may be a file with an error of 0.
- Memorystream attachment =This. Generatepdf ();
- Attachment. Seek (0, seekorigin. Begin );
In this way, you can use the attachment in system. net. Mail to add an attachment.
If streamwriter is used, flush () is required before generation.