I have a PDF file with XFA forms, that I can successfully populate through a dynamically generated XML file.
Now I am trying to insert an image (a hand-made JPG signature file), for which I tried multiple ways, with "partial" luck.
I tried this: How can i set an image to a pdf field in existing pdf file?
And this: How can I insert an image with iTextSharp in an existing PDF?
I meant "partial" luck because the image does show in Foxit Reader, but doesn't show in Acrobat Pro.
Any help will be much, much appreciated.
EDIT:
This is the code I'm using to replace a button field with an image.
private void InsertSignatureIntoBOL(string inputFile, string fieldName, byte[] imageFile, string outputFile)
{
using (PdfStamper stamper = new PdfStamper(new PdfReader(inputFile), File.Create(outputFile)))
{
AcroFields.FieldPosition fieldPosition = stamper.AcroFields.GetFieldPositions(fieldName)[0];
PushbuttonField imageField = new PushbuttonField(stamper.Writer, fieldPosition.position, fieldName);
imageField.Layout = PushbuttonField.LAYOUT_ICON_ONLY;
imageField.Image = iTextSharp.text.Image.GetInstance(imageFile);
imageField.ScaleIcon = PushbuttonField.SCALE_ICON_ALWAYS;
imageField.ProportionalIcon = false;
imageField.Options = BaseField.READ_ONLY;
stamper.AcroFields.RemoveField(fieldName);
stamper.AddAnnotation(imageField.Field, fieldPosition.page);
stamper.Close();
}
}
I also tried this code to add an image to an absolute position"
var pdfContentByte = stamper.GetOverContent(1);
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(Convert.FromBase64String(SignatureHiddenField.Value));
image.SetAbsolutePosition(100, 100);
pdfContentByte.AddImage(image, false);
The only way I can make the images show up in Acrobat Pro is by flattening the form, but I also fill XFA fields in the same form and, when flattened, the XFA fields are shown as empty. As I was mentioning, it works wonderfully in Foxit Phantom, but my main interest is with Acrobat Pro.
Any help would be much, much appreciated.