albilaga
albilaga

Reputation: 439

How to fill form in pdf with image for iText7?

I have pdf with form inside it. I already can set form with value from text. But how if I want to fill the field with image instead with text?

Upvotes: 0

Views: 958

Answers (1)

Jimbo Jones
Jimbo Jones

Reputation: 1002

Replace it with a button, so add a button and insert an image into the button then replace the original formField with a button of the same Key and placement.

        formFields.TryGetValue(key, out var toSet);
        PdfArray sizingArray = toSet.GetWidgets()[0].GetRectangle();
        var width = (float)(sizingArray.GetAsNumber(2).GetValue() - sizingArray.GetAsNumber(0).GetValue());
        var height = (float)(sizingArray.GetAsNumber(3).GetValue() - sizingArray.GetAsNumber(1).GetValue());

        var imagbase64 = imaged.Draw(image);

        var button = PdfFormField.CreatePushButton(
            pdfDoc, new Rectangle(sizingArray.GetAsNumber(0).FloatValue(),
                sizingArray.GetAsNumber(1).FloatValue(),
                width,
                height), key, "");
        button.SetValue(imagbase64);

        form.ReplaceField(key, button);

Upvotes: 1

Related Questions