Replace TextBoxField with Image in PDF Document
Product Version | Product | Author |
---|---|---|
2021.1.212 | RadPdfProcessing | Martin Velikov |
Description
How to replace a TextBoxField with an Image in a PDF document.
Solution
In the example below, we are demonstrating how to find a specific TextBoxField by its name in the imported into a RadFixedDocument PDF document, preserve its size and Position and replace it with an Image.
Replace TextBoxField with Image in Imported PDF Document
RadFixedPage firstPage = document.Pages[0];
Annotation field = firstPage.Annotations.First(a => ((VariableContentWidget)a).Field.Name == "SampleField");
Telerik.Documents.Primitives.Rect fieldRect = field.Rect;
string imagePath = "image.png";
ImageSource newImageSource;
using (FileStream source = File.Open(imagePath, FileMode.Open))
{
newImageSource = new ImageSource(source);
}
SimplePosition simplePosition = new SimplePosition();
simplePosition.Translate(fieldRect.X, fieldRect.Y);
Image newImage = new Image
{
ImageSource = newImageSource,
Position = simplePosition,
Width = fieldRect.Width,
Height = fieldRect.Height
};
firstPage.Annotations.Remove(field);
firstPage.Content.Add(newImage);