---
title: "Attach a file to PDF in C# .NET | Nutrient .NET SDK"
canonical_url: "https://www.nutrient.io/guides/dotnet/editor/attach-a-file/"
md_url: "https://www.nutrient.io/guides/dotnet/editor/attach-a-file.md"
last_updated: "2026-05-21T17:12:02.203Z"
description: "Learn how to attach any type of file to a PDF document programmatically in C# using Nutrient .NET SDK. Embed supporting documents within your PDFs."
---

# Attach a file to a PDF in C#

Nutrient.NET SDK (formerly GdPicture.NET) enables you to attach a file to a PDF in the form of an annotation.

To attach a file to a PDF, follow the steps below.

1. Create a `GdPicturePDF` object.

2. Specify the origin of the coordinate system with the [`SetOrigin`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~SetOrigin.html) method. It requires the `PdfOrigin` enumeration, which accepts the following values:

- `PdfOriginTopLeft`

- `PdfOriginTopRight`

- `PdfOriginBottomRight`

- `PdfOriginBottomLeft`

3. Set the measurement unit used to specify the dimensions of the annotation. The [`SetMeasurementUnit`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~SetMeasurementUnit.html) method takes a member of the `PdfMeasurementUnit` enumeration as an argument. It accepts the following values:
   - `PdfMeasurementUnitCentimeter`
   - `PdfMeasurementUnitMillimeter`
   - `PdfMeasurementUnitInch`
   - `PdfMeasurementUnitPoint`
   - `PdfMeasurementUnitUndefined`

4. Open the file you want to attach in the form of a byte array.

   The file you want to attach must be a binary file.

5. Select the PDF page where you want to add the annotation using the [`SelectPage`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.AnnotationManager~SelectPage.html) method.

6. Use the [`AddFileAttachmentAnnot`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~AddFileAttachmentAnnot.html) method. It accepts the following parameters:

- `Left` — X coordinate of the top-left corner.

- `Top` — Y coordinate of the top-left corner.

- `Width` — Width of the annotation icon.

- `Height` — Height of the annotation icon.

- `Data` — The content of the file associated with the annotation object, which is expressed as a binary value.

- `FileName` — Name of the attached file.

- `Title` — Title of the annotation.

- `Description` — Annotation description.

- color:
  - `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` — 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` — Icon type displayed. This uses the `PdfFileAttachmentAnnotIcon` enumeration. The possible values are the following:
  - `None`
  - `Graph`
  - `Tag`
  - `Paperclip`
  - `PushPin`

To add an image file 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 file as a binary array.
byte[] data = File.ReadAllBytes(filename);
// Select the page to attach the file to.
gdpicturePDF.SelectPage(gdpicturePDF.GetPageCount());
// Add an annotation with the image file.
int annotID = gdpicturePDF.AddFileAttachmentAnnot(Left: 5, Top: 5,
    Width: 2, Height: 4, data, filename, "Attachment", "Attachment for review",
    Color.DarkBlue, 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 file as a binary array.
    Dim data = File.ReadAllBytes(filename)
    ' Select the page to attach the file to.
    gdpicturePDF.SelectPage(gdpicturePDF.GetPageCount())
    ' Add an annotation with the image file.
    Dim annotID As Integer = gdpicturePDF.AddFileAttachmentAnnot(Left:=5, Top:=5,
        Width:=2, Height:=4, data, filename, "Attachment", "Attachment for review",
        Color.DarkBlue, 0.75F, PdfFileAttachmentAnnotIcon.Paperclip)
    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
End Using

```

#### Used Methods

- [`AddFileAttachmentAnnot`]

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

- [`LoadFromFile`](/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)

- [`SelectPage`]

- [`SetOrigin`]

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

#### Related Topics

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

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

## Related pages

- [Add an image to a PDF using C#](/guides/dotnet/editor/add-image-to-pdf.md)
- [Add a page to a PDF or a TIFF image in C# .NET](/guides/dotnet/editor/add-page.md)
- [Add text to an image using C#](/guides/dotnet/editor/add-text-to-image.md)
- [PDF and image editor in C#.NET](/guides/dotnet/editor.md)
- [Add text to PDFs in C#](/guides/dotnet/editor/add-text-to-pdf.md)
- [Add an image to another image using C#](/guides/dotnet/editor/add-image-to-image.md)
- [Merge PDFs in C#](/guides/dotnet/editor/merge-or-combine.md)
- [Modify EXIF metadata using C#](/guides/dotnet/editor/metadata-exif.md)
- [Edit IPTC metadata using C#](/guides/dotnet/editor/metadata-iptc.md)
- [Read and edit PDF page label metadata using C#](/guides/dotnet/editor/metadata-pdf-page-label.md)
- [Read and edit PDF XMP metadata using C#](/guides/dotnet/editor/metadata-xmp.md)
- [Split PDF pages into multiple pages in C#](/guides/dotnet/editor/split.md)
- [Add watermarks to PDFs and images in C#](/guides/dotnet/editor/watermark.md)

