pvginkel / PdfiumViewer

PDF viewer based on Google's PDFium.
Apache License 2.0
967 stars 418 forks source link

PDF file stays locked after a new document load #2

Closed Csontikka closed 9 years ago

Csontikka commented 9 years ago

Hello,

I started to trying to use PdfiumViewer and I think I found some bugs. (or I do something wrong :)) But first of all thank you! This is the fastest solution for PDF viewing I found so far. Keep it up!

So the first problem:

pdfViewer1.Document = PdfDocument.Load("D:\1.pdf"); pdfViewer1.Document = PdfDocument.Load("D:\2.pdf"); //here I cannot delete D:\1.pdf pdfViewer1.Document = null; pdfViewer1.Document.Dispose(); //no change

After the form closed I can delete all of them.

Regards, Csontikka

pvginkel commented 9 years ago

What you're seeing here is that the PdfViewer does not become the owner of the PDF document. What you're supposed to do is dispose of the document yourself. Try changing your code to:

pdfViewer1.Document = PdfDocument.Load("D:\1.pdf");
pdfViewer1.Document.Dispose();
pdfViewer1.Document = PdfDocument.Load("D:\2.pdf");
// Here you should be able to delete D:\1.pdf

Please let me know if this still doesn't work.