This is a migrated thread and some comments may be shown as answers.
Form Field Image
1 Answer 10 Views
This is a migrated thread and some comments may be shown as answers.
Fadi
Top achievements
Rank 1
Veteran
Fadi asked on 11 Jan 2021, 04:28 PM

Do you have any sample code to set a form field with an image so that the image is centered in the form field but keeps it's aspect ratio without going outside the bounding box? Does the image need to be resized first to reduce filesize?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 12 Jan 2021, 09:44 AM

Hello Fadi,

Yes, this is possible. You will need a PushButtonField to hold the image in this case. The image should be smaller than the field rectangle, otherwise, it will be cut off to fit the available size. Here is an example that shows this: 

RadFixedDocument document = new RadFixedDocument();
var page = document.Pages.AddPage();

FormSource form = new FormSource();
form.Size = new System.Windows.Size(1000, 1000);

var editor = new FixedContentEditor(form);
editor.DrawImage(new FileStream(@"..\..\test.png", FileMode.Open));

PushButtonField pushButtonField = new PushButtonField("Test");

PushButtonWidget widget = pushButtonField.Widgets.AddWidget();

widget.Rect = new Rect(25, 25, 805, 612);
widget.HighlightingMode = HighlightingMode.NoHighlighting;

widget.AppearanceCharacteristics.Background = new RgbColor(0, 255, 255, 255);
widget.AppearanceCharacteristics.BorderColor = new RgbColor(0, 255, 255, 255);
widget.Border = new AnnotationBorder(0, AnnotationBorderStyle.None, null);

widget.AppearanceCharacteristics.NormalIconSource = form;
widget.AppearanceCharacteristics.IconAndCaptionPosition = IconAndCaptionPosition.NoCaptionIconOnly;
widget.AppearanceCharacteristics.IconFitOptions.ScalingType = IconScalingType.Proportional;

widget.AppearanceCharacteristics.NormalCaption = null;

widget.RecalculateContent();

document.AcroForm.FormFields.Add(pushButtonField);
page.Annotations.Add(widget);

PdfFormatProvider provider = new PdfFormatProvider();
File.WriteAllBytes(@"..\..\result.pdf", provider.Export(document));

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Asked by
Fadi
Top achievements
Rank 1
Veteran
Answers by
Dimitar
Telerik team
Share this question
or