title: How can I set PdfFormField image in iTextSharp 7 and release the file after using it?
body: <p>I'm having a lot of trouble trying to set a <strong>PdfFormField</strong> 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...):</p>
  
  <pre><code>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();
          }
  </code></pre>
  
  <p>As you can see, I'm setting the pdfButtonFormField image through <strong>pdfButtonFormField.SetImage(imagePath).</strong> 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 <strong>pdfButtonFormField.Flush()</strong> and also <strong>pdfButtonFormField.Release()</strong>. </p>
  
  <p>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.</p>
  
  <p>So please, I'd like to know if theres any way to do it.</p>