How to change a button icon in a PDF form with iText/C#

Viewed 260

I'm trying to retrofit an old C# application that was made using the old Adobe Acrobat API. One of the features of this application was to change the icon of a button and update the caption of the button as well. The caption was overlayed on top of the icon.

Currently, I'm using iText 7 and C# to program the application. I have most of the functionality ready, but I can't figure out how to add a caption and icon to a button. I was able to figure out how to add a caption and an icon seperately, but when I try to combine the code snippets, the icon seems to cover the caption.

PdfButtonFormField button = (PdfButtonFormField)pdfForm.GetField(fieldName);
button.SetImage(tempFileLOGO);

var buttonObj = button.GetPdfObject();
buttonObj.GetAsDictionary(PdfName.MK).Put(PdfName.TP, new PdfNumber((int)PushButtonLayouts.LABEL_OVER));

pdfForm.ReplaceField(fieldName, button);

var fields = pdfForm.GetFormFields();
foreach (var f in fields)
{
    if (f.Key.StartsWith("sign_"))
    {
        f.Value.SetValue(fieldValue);
    }
}

This code causes the icon to be placed on the button, but I don't see the caption text (variable name "fieldValue")

Any help would be appreciated!

Thanks!

1 Answers
Related