# Create an annotation in a PDF using C#

To create an annotation in a PDF document, follow the steps below:

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 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 the [`PdfMeasurementUnit` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfMeasurementUnit.html).

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

6. Optional: Specify the font type. For more information, refer to the [Font Type](/guides/dotnet/editor/add-text-to-pdf.md) section of the guide on adding text to PDFs.

7. Add the annotation with any of the following methods:
   - [`AddFreeTextAnnotation`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddFreeTextAnnotation.html)
   - [`AddSquareAnnotation`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddSquareAnnotation.html)
   - [`AddCircleAnnotation`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddCircleAnnotation.html)
   - [`AddStampAnnotation`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddStampAnnotation.html)
   - [`AddStickyNoteAnnotation`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddStickyNoteAnnotation.html)
   - [`AddLineAnnotation`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddLineAnnotation.html)
   - [`AddLinkAnnotation`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddLinkAnnotation.html)
   - [`AddLinkToPageAnnotation`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddLinkToPageAnnotation.html)
   - [`AddLinkToWebAnnotation`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddLinkToWebAnnotation.html)
   - [`AddFreeTextAnnotation`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddFreeTextAnnotation.html)
   - [`AddFreeTextAnnotation`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddFreeTextAnnotation.html)

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

All methods that create a new annotation return an integer value, which is the annotation’s index. Recommended: Save the annotation index to a variable so that you can later reference that annotation.

### C#

```csharp

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Set the origin of the coordinate system.
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
// Set the measurement unit to centimeters.
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
// Select the first PDF page.
gdpicturePDF.SelectPage(1);
// Set the text content and determine its size.
float fontSize = 16;
string fontResName = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica);
string text = "Text annotation example.";
float textWidth = gdpicturePDF.GetTextWidth(fontResName, fontSize, text);
float textHeight = gdpicturePDF.GetTextHeight(fontResName, fontSize, false);
// Add the free text annotation.
int annotIndex = gdpicturePDF.AddFreeTextAnnotation(1, 2, textWidth + 0.5f, textHeight + 0.5f, true,
    "Annotation Example", "Example", text,
    fontResName, fontSize, 0, 0, 200, 100, 100, 100, 100);
gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");

```

### VB.NET

```vb

Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Set the origin of the coordinate system.
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
    ' Set the measurement unit to centimeters.
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
    ' Select the first PDF page.
    gdpicturePDF.SelectPage(1)
    ' Set the text content and determine its size.
    Dim fontSize As Single = 16
    Dim fontResName As String = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica)
    Dim text = "Text annotation example."
    Dim textWidth As Single = gdpicturePDF.GetTextWidth(fontResName, fontSize, text)
    Dim textHeight As Single = gdpicturePDF.GetTextHeight(fontResName, fontSize, False)
    ' Add the free text annotation.
    Dim annotIndex As Integer = gdpicturePDF.AddFreeTextAnnotation(1, 2, textWidth + 0.5F, textHeight + 0.5F, True,
        "Annotation Example", "Example", text,
        fontResName, fontSize, 0, 0, 200, 100, 100, 100, 100)
    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
End Using

```

#### Used methods

- [`AddFreeTextAnnotation`]

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

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

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

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

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

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

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

- [`SetOrigin`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~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

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

