using iTextSharp.text; using iTextSharp.text.pdf; // Create a new instance of Document class Document document = new Document(); // Do some tasks here // Release all the resources used by Document object document.Dispose();
using iTextSharp.text; using iTextSharp.text.pdf; using System.IO; // Create a new instance of Document class Document document = new Document(); // Create a new instance of a PdfWriter object PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("example.pdf", FileMode.Create)); // Do some tasks here // Release all the resources used by the PdfWriter object writer.Dispose(); // Release all the resources used by Document object document.Dispose();In this example, we have created a new instance of the Document class and a PdfWriter object. We have set the output file stream to create a new PDF file and then performed some actions on the document instance. Finally, we have released all the resources used by the PdfWriter and Document objects. Overall, the iTextSharp package library is a useful tool in C# for generating and manipulating PDF files. The Document.Dispose() method is critical in releasing all the resources used by the Document object, ensuring that the program runs smoothly without any memory leakage.