This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/dotnet/editor/attach-a-file.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Attach a file to PDF in C# .NET | Nutrient .NET SDK

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

Download sample

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 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 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 method.

  6. Use the AddFileAttachmentAnnot method. It accepts the following parameters:

    • Left — The horizontal coordinate of the annotation corner closest to the origin.
    • Top — The vertical coordinate of the annotation corner closest to the origin.
    • Width — The width of the annotation icon.
    • Height — The height of the annotation icon.
    • Data — The content of the file associated with the annotation object, as a byte array.
    • FileName — The name of the attached file.
    • Title — The title of the annotation. By convention, this is the author.
    • Description — The description of the attached file.
    • The annotation color, in one of the following forms:
      • Red, Green, Blue — RGB values (from 0 to 255).
      • Cyan, Magenta, Yellow, Black — CMYK values (from 0 to 255).
      • Color — A GdPictureColor object. For more information, refer to the color object guide.
    • Opacity — The opacity of the annotation, where 0 means fully transparent and 1 means fully visible. Use the f suffix to convert the double value to float (0.75f).
    • AnnotIcon — The 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:

Register the SDK license before running SDK operations. For setup details, refer to the getting started with .NET SDK guide.

using GdPicture14;
using GdPicture14.Imaging;
LicenseManager license = new LicenseManager();
license.RegisterKEY("");
using GdPicturePDF gdpicturePDF = new GdPicturePDF();
string filename = @"input.jpg";
gdpicturePDF.LoadFromFile(@"input.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",
0, 0, 128, 0.75f, PdfFileAttachmentAnnotIcon.Paperclip);
gdpicturePDF.SaveToFile(@"output.pdf");