I'm having a lot of trouble trying to set a PdfFormField image and release the file used by the itext process. Here is what I'm doing now (setting the image itself works just fine, but the file still being used by the process...):
public void SetImageField(string idFormField, string imagePath)
{
PdfButtonFormField pdfButtonFormField = (PdfButtonFormField)_pdfAcroForm
.GetField(idFormField);
if (pdfButtonFormField == null)
throw new InstanceNotFoundException("Não foi encontrado o campo de assinatura no pdf!");
pdfButtonFormField
.SetImage(imagePath);
pdfButtonFormField
.SetBorderWidth(0);
pdfButtonFormField.Flush();
pdfButtonFormField.Release();
}
As you can see, I'm setting the pdfButtonFormField image through pdfButtonFormField.SetImage(imagePath). The thing is, I need to delete this file (imagePath) after using it, and it seems that itext process still using the resource, even if I call pdfButtonFormField.Flush() and also pdfButtonFormField.Release().
So you may say, "why don't you just open a filestream, and call fileStream.Dispose after using?". Because the file itself is not in my hands, its being managed by itext api.
So please, I'd like to know if theres any way to do it.