---
title: "Attach an image to an annotation in C# .NET | Nutrient .NET SDK"
canonical_url: "https://www.nutrient.io/guides/dotnet/annotations/attach-an-image/"
md_url: "https://www.nutrient.io/guides/dotnet/annotations/attach-an-image.md"
last_updated: "2026-05-21T17:12:02.195Z"
description: "Learn how to efficiently attach files and images in your .NET applications with our comprehensive guide. Step-by-step instructions included!"
---

# Attach an image to an annotation in C#

### Attach a File

[Attach a File](https://www.nutrient.io/guides/dotnet/annotations/attach-a-file.md)

### Attach an Image

[Attach an Image](https://www.nutrient.io/guides/dotnet/annotations/attach-an-image.md)

To add an image in a form of a PDF annotation, follow these steps:

1. Create a `GdPicturePDF` object.

2. Load the PDF file with the [`LoadFromFile` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~LoadFromFile.html).

3. Set the origin of the coordinate system with the [`SetOrigin` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetOrigin.html). This method requires a member of the [`PDFOrigin` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfOrigin.html).

4. Set the measurement unit with the [`SetMeasurementUnit` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetMeasurementUnit.html) to specify the annotation’s dimensions and position. This method uses a member of the [`PdfMeasurementUnit` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfMeasurementUnit.html).

5. Select the PDF page to place the annotation on using the [`SelectPage` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SelectPage.html).

6. Load the image to a byte array.

7. Add the annotation with the attached image using the [`AddFileAttachmentAnnot` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddFileAttachmentAnnot.html). This method uses the following parameters:
   - `Left` — The X coordinate of the top-left corner.
   - `Top` — The Y coordinate of the top-left corner.
   - `Width` — The width of the annotation icon.
   - `Height` — The height of the annotation icon.
   - `Data` — The content of the image associated with the annotation object, which is expressed as a binary array.
   - `FileName` — The full path to the attached image.
   - `Title` — The title of the newly added annotation object. By convention, this represents the author of the annotation.
   - `Description` — The description of the file associated with the annotation object.
   - The annotation icon’s color expressed in one of the following ways:
     - `Red`, `Green`, `Blue` — RGB values (from `0` to `255`).
     - `Cyan`, `Magenta`, `Yellow`, `Black` — CMYK values (from `0` to `255`).
     - `Color` object — For more information, refer to the [color object](https://www.nutrient.io/guides/dotnet/editor/manipulation/colors.md#color-object) guide.
   - `Opacity` — The opacity value of the annotation, where `0` means full transparency and `1` means fully visible. Use the `f` suffix to convert the double value to float (`0.75f`).
   - `AnnotIcon` — The icon type displayed. It uses the [`PdfFileAttachmentAnnotIcon` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfFileAttachmentAnnotIcon.html). The possible values are the following:
     - `None`
     - `Graph`
     - `Tag`
     - `Paperclip`
     - `PushPin`

8. Save the PDF document to a file with the [`SaveToFile` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SaveToFile.html).

To add an image as an annotation to the last page of a PDF, use the following code:

### C#

```csharp

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
string filename = @"C:\temp\source.jpg";
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Set the origin of the coordinate system to the bottom-left corner.
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginBottomLeft);
// Set the measurement unit to centimeters.
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
// Load the image as a binary array.
byte[] data = File.ReadAllBytes(filename);
// Select the page to attach the image to.
gdpicturePDF.SelectPage(gdpicturePDF.GetPageCount());
// Add an annotation with the image.
gdpicturePDF.AddFileAttachmentAnnot(Left: 5, Top: 5, Width: 2, Height: 4,
    data, filename, "Nutrient", "Attachment for review",
    173, 216, 230, 0.75f, PdfFileAttachmentAnnotIcon.Paperclip);
gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");

```

### VB.NET

```vb

Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    Dim filename = "C:\temp\source.jpg"
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Set the origin of the coordinate system to the bottom-left corner.
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginBottomLeft)
    ' Set the measurement unit to centimeters.
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
    ' Load the image as a binary array.
    Dim data = File.ReadAllBytes(filename)
    ' Select the page to attach the image to.
    gdpicturePDF.SelectPage(gdpicturePDF.GetPageCount())
    ' Add an annotation with the image.
    gdpicturePDF.AddFileAttachmentAnnot(Left:=5, Top:=5, Width:=2, Height:=4,
        data, filename, "Nutrient", "Attachment for review",
        173, 216, 230, 0.75F, PdfFileAttachmentAnnotIcon.Paperclip)
    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
End Using

```

#### Used methods

- [`AddFileAttachmentAnnot`](/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~AddFileAttachmentAnnot.html)

- [`GetPageCount`](/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~GetPageCount.html)

- [`LoadFromFile`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~LoadFromFile.html)

- [`ReadAllBytes`](https://learn.microsoft.com/en-us/dotnet/api/system.io.file.readallbytes?view=net-7.0)

- [`SaveToFile`](/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~SaveToFile.html)

- [`SelectPage`](/api/gdpicture/GdPicture.NET.14~GdPicture14.AnnotationManager~SelectPage.html)

- [`SetMeasurementUnit`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetMeasurementUnit.html)

- [`SetOrigin`](/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~SetOrigin.html)

#### Related topics

- [Load a file](/guides/dotnet/load-a-file.md)

- [Save a file](/guides/dotnet/save-a-file.md)
---

## Related pages

- [Custom annotations](/guides/dotnet/annotations/custom-annotations.md)
- [Annotate on images in C# .NET](/guides/dotnet/annotations/annotate-on-images.md)
- [Attach a file to an annotation in C#](/guides/dotnet/annotations/attach-a-file.md)
- [Create an annotation in a PDF using C#](/guides/dotnet/annotations/create.md)
- [Edit PDF annotations in C#](/guides/dotnet/annotations/edit.md)
- [Export XMP annotation data in C# .NET](/guides/dotnet/annotations/export-xmp.md)
- [Export annotation data from PDFs in C# .NET](/guides/dotnet/annotations/export-pdf.md)
- [Flatten PDF annotations in C# .NET](/guides/dotnet/annotations/flatten.md)
- [Get PDF annotation properties in C# .NET](/guides/dotnet/annotations/get-properties.md)
- [Import XFDF annotation data to PDFs in C# .NET](/guides/dotnet/annotations/import-xfdf.md)
- [Remove PDF annotations in C# .NET](/guides/dotnet/annotations/remove.md)
- [PDF annotations in C#.NET](/guides/dotnet/annotations.md)
- [Add PDF actions using C# in form fields](/guides/dotnet/annotations/pdf-actions-support.md)
- [Import XMP annotation data to PDF or image in C#](/guides/dotnet/annotations/import-xmp.md)
- [Stamp a PDF document in C# .NET](/guides/dotnet/annotations/stamp-a-document.md)
- [XMP annotations in C# .NET](/guides/dotnet/annotations/xmp-annotations.md)

