Freeing document resources

Hi

I'm evaluating the trial version of Essential PDF for usage with our tool for software integration.

I need to write a proof of concept dll which will serve as a translator between your dll's and our app.

One of the problems that came up is freeing resources used by Essential PDF.

C# code example:

public string GetFieldNameByIndex(int index)
{
//load document
PdfLoadedDocument doc = new PdfLoadedDocument(_pdfLoadPath);
string name = doc.Form.Fields[index].Name;
doc.Close();
return name;
}
public int GetFieldCount()
{
//load document
PdfLoadedDocument doc = new PdfLoadedDocument(_pdfLoadPath);
int count = doc.Form.Fields.Count;
doc.Close();
return count;
}


Above 2 public methods are visible in our application. I can invoke any of them once and they run as intended. But when I try to run them one after another first runs correctly, but second one gives an error:

The process cannot access the file 'C:\newformform.pdf' because it is being used by another process.

How do I free the document handled by Essential PDF libraries?

Thank you.



4 Replies

GM Geetha M Syncfusion Team December 23, 2008 11:55 AM UTC

Hi Lukasz,

Thank you for your interest in Syncfusion products.

When you load a file, it actually loads in the memory and be there till the operations are performed and will be free from the memory only when you call doc.Close();. So you may not allowed / it is not possible to open the file that is already opened. This is equivalent to open a file when it is already opened using a different application. In order to avoid the problem, you could open the file once and close it after manipulation; and then open it again for the second call.

Please let me know if you have any other questions.

Regards,
Geetha



LD Lukasz Dejneka December 23, 2008 12:13 PM UTC

Hi

Thank you for your answer.

The problem is that I already call doc.close() after operations are finished, as you can see from the code snippet I included. Apparently even when I call it, the resource is still unavailable.






GM Geetha M Syncfusion Team December 23, 2008 12:26 PM UTC

Hi Lukasz,

Thank you for the update.

I was able to see the issue.

Please use doc.Close(true); instead of doc.Close(); to solve it.

Regards,
Geetha



LD Lukasz Dejneka December 23, 2008 12:56 PM UTC

Hi

Thank you kindly for your help. Resources are freed now properly.

With regards and holiday best wishes.

Lukasz


Loader.
Up arrow icon