Legacy notice!

iText 5 is the previous major version of iText's leading PDF SDK. iText 5 has been EOL, and is no longer developed. Switch your project to iText 7, integrating the latest developments.
Check related iText 7 content!

I'm trying to fill out a PDF form using the AcroFields class. I'm able to add text data perfectly, but I'm having issues adding images. How is this done?

Posted on StackOverflow on Apr 17, 2013 by Anil M

The "official" way to do this, is to have a Button field as placeholder for the image, and to replace the "icon" of the button like this:

PushbuttonField ad = form.getNewPushbuttonFromField(imageFieldName);
ad.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);
ad.setProportionalIcon(true);
ad.setImage(Image.getInstance("E:/signature/signature.png"));
form.replacePushbuttonField("advertisement", ad.getField());

See ReplaceIcon.java for the full code sample.