Skip to main content

Dispose PDF after Printing

Version: 4.0

Dispose PDF after Printing

When you are finished printing a PDF document, it is recommended that you explicitly release the resources associated with the print operation by calling either the Dispose method of the PrintJob class or the Dispose method of an InputPdf class instance.

Calling the Dispose method releases unmanaged resources used during printing and helps ensure that file handles, printer resources, and memory are properly cleaned up after the print job completes. The following examples illustrate both approaches.

info

Calling Dispose() on an InputPdf instance releases the resources associated with that specific PDF document, such as the underlying PDF data, file handles, and related unmanaged resources used by the InputPdf object.

Calling Dispose() on a PrintJob releases the resources associated with the entire print job, including resources used by the print operation itself and any associated PDF content managed by the PrintJob.

From PrintJob​

PrintJob printJob = new PrintJob(Printer.Default, inputPath);
printJob.Print();
printJob.Dispose();
Dim printJob As New PrintJob(Printer.Default, inputPath)
printJob.Print()
printJob.Dispose()

[DisposeExample.cs](https://github.com/DynamicPDF/print-manager-dotnet-core/blob/master/print-manager-dotnet-core-cs/DisposeExample.cs){#gitlink-id target=_blank}


[DisposeExample.vb](https://github.com/DynamicPDF/print-manager-dotnet-core/blob/master/print-manager-dotnet-core-vb/DisposeExample.vb){#gitlink-id target=_blank}

From InputPdf​

InputPdf pdf = new InputPdf(pdfFilePath);
PrintJob printJob = new PrintJob(Printer.Default, pdf);
printJob.Print();
pdf.Dispose();
Dim pdf As InputPdf = New InputPdf(pdfFilePath)
Dim printJob As PrintJob = New PrintJob(Printer.Default, pdf)
printJob.Print()
pdf.Dispose()

[DisposeExample.cs](https://github.com/DynamicPDF/print-manager-dotnet-core/blob/master/print-manager-dotnet-core-cs/DisposeExample.cs){#gitlink-id target=_blank}


[DisposeExample.vb](https://github.com/DynamicPDF/print-manager-dotnet-core/blob/master/print-manager-dotnet-core-vb/DisposeExample.vb){#gitlink-id target=_blank}