New to Telerik Document ProcessingStart a free 30-day trial

Adding an Image Border in PdfProcessing

Updated on Jun 9, 2026

Environment

VersionProductAuthor
2025.3.806RadPdfProcessingDesislava Yordanova

Description

This article shows how to add borders around images in a generated PDF document.

Solution

To draw borders around images, use one of the following approaches:

Approach 1: Using a Table with Borders

Insert a table with a single TableCell and place the image in the cell:

csharp
RadFixedDocument document = new RadFixedDocument();
RadFixedPage page = document.Pages.AddPage(); 
FixedContentEditor editor = new FixedContentEditor(page);
int thickness = 3;

RgbColor bordersColor = new RgbColor(255, 0, 0);
Border border = new Border(thickness, Telerik.Windows.Documents.Fixed.Model.Editing.BorderStyle.Single, bordersColor);
TableCellBorders tableCellsBorder = new TableCellBorders(border, border, border, border, null, null);
Table table = new Table();
table.Borders = new TableBorders(border);
table.DefaultCellProperties.Borders = tableCellsBorder;
TableRow imgRow = table.Rows.AddTableRow();
TableCell imgCell = imgRow.Cells.AddTableCell();
imgCell.Borders = tableCellsBorder;
Block imageBlock = imgCell.Blocks.AddBlock();
imageBlock.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
imageBlock.InsertImage(new FileStream("banner.png", FileMode.Open));

table.Draw(editor, new Rect(5, 5, page.Size.Width, page.Size.Height));

PdfFormatProvider pdfProvider = new PdfFormatProvider();
using (Stream output = File.OpenWrite(@"..\..\exported.pdf"))
{
    pdfProvider.Export(document, output);
}

Using a Table with Borders ><

Approach 2: Using FixedContentEditor to Draw a Rectangle Border

As an alternative, use the FixedContentEditor to draw a rectangular border around the image:

csharp
RadFixedDocument document = new RadFixedDocument();
RadFixedPage page = document.Pages.AddPage();
FixedContentEditor editor = new FixedContentEditor(page);

double thickness = 3; 
double x = 10; 
double y = 10; 
double width = 150; 
double height = 150; 
string imagePath = "banner.png";

// Determine image dimensions
using (FileStream fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read))
{
    using (var img = System.Drawing.Image.FromStream(fs, false, false))
    {
        width = img.Width;
        height = img.Height;
    }
}

// Draw rectangle border
editor.Position.Translate(x - thickness, y - thickness);
editor.SaveGraphicProperties();
editor.GraphicProperties.StrokeColor = new RgbColor(255, 0, 0);
editor.GraphicProperties.StrokeThickness = thickness;
editor.DrawRectangle(new Rect(0, 0, width + thickness * 2, height + thickness * 2));
editor.RestoreGraphicProperties();

// Draw image
using (FileStream fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read))
{
    editor.Position.Translate(x, y);
}

PdfFormatProvider pdfProvider = new PdfFormatProvider();
using (Stream output = File.OpenWrite(@"..\..\exported.pdf"))
{
    pdfProvider.Export(document, output);
}

Using a FixedContentEditor to Draw the Image Border ><

See Also