New to Telerik Document Processing? Download free 30-day trial

Replace Image in PDF Document

Product Version Product Author
2021.1.212 RadPdfProcessing Martin Velikov

Description

How to replace image in a PDF document.

Solution

In the example below, we are demonstrating how to find a specific image in the imported into a RadFixedDocument PDF document, preserve its size and Position and replace it with another Image.

Replace Image in Imported PDF Document

RadFixedPage firstPage = document.Pages[0]; 
 
Image image = firstPage.Content.First(ce => ce is Image) as Image; 
 
string newImagePath = "image.png"; 
ImageSource newImageSource; 
using (FileStream source = File.Open(newImagePath, FileMode.Open)) 
{ 
    newImageSource = new ImageSource(source); 
} 
 
Image newImage = new Image 
{ 
    ImageSource = newImageSource, 
    Position = image.Position, 
    Width = image.Width, 
    Height = image.Height 
}; 
 
int imageIndex = firstPage.Content.IndexOf(image); 
firstPage.Content.RemoveAt(imageIndex); 
firstPage.Content.Add(newImage); 
In this article
Not finding the help you need? Improve this article