Remove image after using FillImageField

We have a business process where a form is “signed”, and this is done by calling Form.FillImageField() The business process enables going back a step in the workflow and removing the signature. We were able to do this by filling the field again with a blank png. However, after doing that and applying the original signature, the image is black on the form.

Is there an alternate approach to remove the image?

I have created a test project that I can share to reproduce.

@Johnwpowellryan

Would you please share your sample PDF documents along with complete code snippet that you are using? We will test the scenario in our environment and address it accordingly.

FillImage2.zip (828.8 KB)

Thanks for looking into this. I have attached the sample project, and here’s the relevant code:

var assembly = Assembly.GetExecutingAssembly();

        // Step 1, create a form from a template
        var templateStream = assembly.GetManifestResourceStream("FillImage.XFAFormTemplate.pdf");
        var template = new Document(templateStream);

        var output = new Document();
        output.Pages.Add(template.Pages);

        // append a report to it
        var reportStream = assembly.GetManifestResourceStream("FillImage.Report.pdf");
        var report = new Document(reportStream);

        output.Pages.Add(report.Pages);

        output.Save("Step1.pdf");

        // step 2, add a signature image
        using (var outputStream = File.Open("Step1.pdf", FileMode.Open))
        {
            var outputForm = new Aspose.Pdf.Facades.Form(outputStream);

            var signature = assembly.GetManifestResourceStream("FillImage.Signature.png");

            outputForm.FillImageField("topmostSubform[0].Page1[0].Signature[0]", signature);

            outputForm.Save("Step2.pdf");
        }

        // step 3, business process found an issue, so remove the signature by filling with blank signature
        using (var outputStream = File.Open("Step2.pdf", FileMode.Open))
        {
            var outputForm = new Aspose.Pdf.Facades.Form(outputStream);

            var signature = assembly.GetManifestResourceStream("FillImage.blankSignature.png");

            outputForm.FillImageField("topmostSubform[0].Page1[0].Signature[0]", signature);

            outputForm.Save("Step3.pdf");
        }

        // step 4, business process issue fixed, add signature image back, result is black box displayed
        using (var outputStream = File.Open("Step2.pdf", FileMode.Open))
        {
            var outputForm = new Aspose.Pdf.Facades.Form(outputStream);

            var signature = assembly.GetManifestResourceStream("FillImage.Signature.png");

            outputForm.FillImageField("topmostSubform[0].Page1[0].Signature[0]", signature);

            outputForm.Save("Step4.pdf");
        }

@Johnwpowellryan

We were able to reproduce the issue in our environment with Aspose.PDF for .NET 20.12. We also tried following method to remove the image but did not get much success:

Document doc = new Document(outputStream);
using (Aspose.Pdf.Facades.PdfFileSignature pdfSign = new Aspose.Pdf.Facades.PdfFileSignature(doc))
{
 var signatures = pdfSign.GetSignNames();
 if (signatures.Count > 0)
 {
  for (int i = 0; i < signatures.Count; i++)
  {
   pdfSign.RemoveSignature(signatures[i].ToString(), false);
  }
 }
}

Therefore, have logged an issue as PDFNET-49180 in our issue tracking system for the sake of correction. It looks like that the black image is a resultant of multiple images at same location. The previously added images are not being removed and next images are being added on a different layer. Nevertheless, we will further investigate it and fix it on first come first serve basis and let you know once it is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

1 Like

Is this scheduled for a particular release so we can put it on our roadmap?

@Johnwpowellryan

The issue has recently been logged in our issue management system and is pending for an analysis at the moment. It will be investigated and fixed on a first come first serve basis. As soon as we make some significant progress towards its resolution or have some ETA in this regard, we will inform you in this forum thread. Please give us some time.

We apologize for the inconvenience.