Using the PDFDoc of the Merger library's to iterate through its page collection. For each page using the GetText() method.
Later when attempting to delete these pdfs; I can not because they are still open. Is there an explicit close method for the document?
I do have a try/catch/finally that sets the PDFDoc to null; but that doesnt seem to be enough.
Thank you
ceTe.DynamicPDF.40 8.0.0.40
Merger PDFDoc leaving files open
Re: Merger PDFDoc leaving files open
Support · Apr 8, 2016Hello,
There is no close method available on PdfDocument object. If you set the PdfDocument object to null, .Net garbage collector will clean up the file resources but it may not do it right away, hence you are unable to delete the file. To be able to delete the PDF right away, load the PDF into a byte array and then create the PdfDocument with that byte array as shown below.
string path = @"file path here";
byte[] pdfBytes = File.ReadAllBytes(path);
PdfDocument pdf = new PdfDocument(pdfBytes);
foreach (PdfPage p in pdf.Pages)
{
string txt = p.GetText();
}
File.Delete(path);
Thanks,
ceTe Software Support Team.