Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dispose itextSharp objects

I want to dispose itextsharp document, PdfWriter, Font Color objects to be disposed explicitly. Can anyone please tell me how to achieve the same.

like image 906
Anant Avatar asked Nov 28 '25 06:11

Anant


1 Answers

I just looked through some code (had a free couple of minutes). It looks like PdfWriter implements IDisposable (or at least IDocListener does, which if you go far enough down, PdfWriter inherits from). You should just be able to call Dispose() (or wrap it in a using statement):

using(PdfWriter MyWriter=PdfWriter.GetInstance(Document,Stream))
{
...
}

Same with most everything else (Document, etc.). Although that seems to be only with newer versions (the 4.0 version in one of my projects doesn't seem to use IDisposable for PdfWriter, etc.)

like image 133
JaCraig Avatar answered Nov 29 '25 19:11

JaCraig



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!