Extracting image from XFA Form pdf

Hi Team!

How could I extract image from a pdf that is in a XFA Form? Because ImagePlacementAbsorber doesn’t find any from the following pdf.

DynamicXFAToAcroForm.pdf (144.0 KB)

@erdeiga

We have logged an issue as PDFNET-50362 in our issue management system after replicating the it in our environment. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

@asad.ali

I have another pdf wich contains an Image acro form field. How could I access and replace this image?

ImageFormField.pdf (39.6 KB)

@erdeiga

We tried and found that Aspose.PDF was recognizing it as ButtonField. We used the below code snippet to set its image but API threw an Exception:

var pdf = new Aspose.Pdf.Document(dataDir + "ImageFormField.pdf");
var fields = pdf.Form.Fields; // cache Form.Fields property in a local variable

for (int i = 0; i < fields.Length; i++) // 7 seconds to exit loop
{
 var f = fields[i];
 ButtonField bf = (ButtonField)fields[i];
 bf.AddImage(new Bitmap(dataDir + "aspose.jpg"));
}

We were however able to extract the existing image using the below code:

var pdf = new Aspose.Pdf.Document(dataDir + "ImageFormField.pdf");
var fields = pdf.Form.Fields; // cache Form.Fields property in local variable

for (int i = 0; i < fields.Length; i++) // 7 seconds to exit loop
{
 var f = fields[i];
 ButtonField bf = (ButtonField)fields[i];
 XImage img = bf.NormalIcon.Resources.Images[1];
 img.Save(new FileStream(dataDir + "img789654.jpg", FileMode.CreateNew), ImageFormat.Jpeg);
}

Therefore, whole scenario has been logged in our issue tracking system under the ticket ID PDFNET-50369. We will further look into its details and let you know as soon as the ticket is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

1 Like