# Adding an Image Border in PdfProcessing

<style>
img[alt$="><"] {
  border: 1px solid lightgrey;
}
</style>

## Environment

| Version    | Product          | Author                                                                          |
| ---------- | ---------------- | ------------------------------------------------------------------------------- |
| 2025.3.806 | RadPdfProcessing | [Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova) |

## Description

This article shows how to add borders around [images](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/image) 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`](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/editing/table/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 ><](https://www.telerik.com/document-processing-libraries/documentation/assets/6950587f1fb0d5157d933d75e6145c02/image-table-cell-border.png)

### Approach 2: Using FixedContentEditor to Draw a Rectangle Border

As an alternative, use the [`FixedContentEditor`](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/editing/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 ><](https://www.telerik.com/document-processing-libraries/documentation/assets/359741cf4722fe266ff82f93a90ce79d/image-fixedcontenteditor-border.png)

## See Also

* [FixedContentEditor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/editing/fixedcontenteditor)
* [TableCell](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/editing/table/tablecell)
* [PDF Images](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/model/image)
