# Fill and sign PDFs in C# .NET

To sign a PDF with a digital signature, follow the steps below:

1. Load the source document with a signature field by passing its path to the [`LoadFromFile` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~LoadFromFile.html) of the [`GdPicturePDF` object](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF.html).

2. Set the certificate contained in the digital ID stored in the `PCKS#12` file or a `Stream` object with the [`SetSignatureCertificateFromP12` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetSignatureCertificateFromP12.html).

3. Recommended: Specify the signature information with the [`SetSignatureInfo` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetSignatureInfo.html). It requires the following string parameters:

- `Name` — The person or authority signing the document.

- `Reason` — The reason for signing.

- `Location` — The physical location where the signing takes place.

- `ContactInfo` — The contact information of the signer.

4. Get the signature’s location with the [`SetSignaturePosFromPlaceHolder` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetSignaturePosFromPlaceHolder.html). It requires either the [signature ID or the signature name](https://www.nutrient.io/guides/dotnet/signatures/signature-field/get-signature-field-properties.md) as its parameter.

5. Configure the text with the [`SetSignatureText` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetSignatureText.html). It uses the following parameters:

- `Text` — The text to be displayed. If this parameter is an empty string, the text displays the data from the `SetSignatureInfo` method.

- `FontResName` — The font name used. Use either the [`AddTrueTypeFont` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddTrueTypeFont.html) or the [`AddStandardFont` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddStandardFont.html). If this parameter is an empty string, the predefined font is used.

- `FontSize` — The text font size in points.

- Font color — The font color can be set in one of the following ways: a `Color` object, a set of four byte parameters (`Cyan`, `Magenta`, `Yellow`, `Black`), or a 32-bit signed integer.

- `AlignHorz` — The horizontal text alignment within the bounding box. Use the [`TextAlignment` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.TextAlignment.html).

- `AlignVert` — The vertical text alignment within the bounding box. Use the [`TextAlignment` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.TextAlignment.html).

- `TextDecorationStyle` — Optional: A member of the [`PdfTextDecorationStyle` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfTextDecorationStyle.html). It specifies if the text has an overline, strikethrough, or underline.

- `ShowText` — A Boolean value that specifies whether the text is displayed.

  To use the text settings defined in the signature field, refer to the guide on [getting text settings from a signature field](https://www.nutrient.io/guides/dotnet/signatures/signature-field/get-signature-field-properties.md).

6. Apply the signature with the [`ApplySignature` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~ApplySignature.html) using the specified settings, and save the PDF document to a file or a `Stream` object. It requires the following parameters:
   - `OutputFileName` or `OutputStream` — Either the path to the output file or a `Stream` object.
   - `SignatureMode` — A member of the [`PdfSignatureMode` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfSignatureMode.html) that specifies the electronic signature technology used in the signing process.
   - `Linearization` — Specifies if the output PDF document is linearized.

To sign a signature field with a digital signature in the form of an image, follow the steps in the [Signing a Digital Signature with an Image](https://www.nutrient.io/guides/dotnet/signatures/digital-signatures/add-a-digital-signature.md#signing-a-digital-signature-with-an-image) section of the guide on adding digital signatures. To specify the signature’s position, use the [`SetSignaturePosFromPlaceHolder` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetSignaturePosFromPlaceHolder.html) instead of `SetSignaturePos`.

You can only add digital signatures to non-encrypted documents.

To sign a signature form field in a PDF with a digital signature, use the following code:

### C#

```csharp

using GdPicturePDF gdPicturePDF = new GdPicturePDF();
gdPicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Set the certificate from a file.
gdPicturePDF.SetSignatureCertificateFromP12(@"C:\temp\certificate.pfx", "nutrient");
// Set the signature position from the signature field.
gdPicturePDF.SetSignaturePosFromPlaceHolder("Signature1");
// Configure the signature text.
gdPicturePDF.SetSignatureText("John Smith", "", 12, GdPictureColor.Red,
    TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, true);
// Apply the signature and save the PDF document.
gdPicturePDF.ApplySignature(@"C:\temp\output.pdf",
    PdfSignatureMode.PdfSignatureModeAdobePPKMS, false);

```

### VB.NET

```vb

Using gdPicturePDF As GdPicturePDF = New GdPicturePDF()
    gdPicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Set the certificate from a file.
    gdPicturePDF.SetSignatureCertificateFromP12("C:\temp\certificate.pfx", "nutrient")
    ' Set the signature position from the signature field.
    gdPicturePDF.SetSignaturePosFromPlaceHolder("Signature1")
    ' Configure the signature text.
    gdPicturePDF.SetSignatureText("John Smith", "", 12, GdPictureColor.Red,
        TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, True)
    ' Apply the signature and save the PDF document.
    gdPicturePDF.ApplySignature("C:\temp\output.pdf",
        PdfSignatureMode.PdfSignatureModeAdobePPKMS, False)
End Using

```

#### Used methods

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

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

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

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

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

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

#### Related topics

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

## Related pages

- [Get signature field properties in C#](/guides/dotnet/signatures/signature-field/get-signature-field-properties.md)
- [Add a signature field to a PDF in C#](/guides/dotnet/signatures/signature-field/add-a-signature-field.md)
- [Remove a signature field from a PDF in C#](/guides/dotnet/signatures/signature-field/remove-signature-field.md)

