> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/core/digital-signature/sign-pdf.md).

# Sign a PDF document on Server/Desktop

Learn how to digitally sign PDF files using the Apryse SDK. Add approval signatures with a Digital Certificate for authenticity and security. Full code sample provided. The Apryse Server SDK streamlin

{% hint style="info" %}
**Requirements**

*These packages are required to use these features in production. Trial keys have unlimited access to all features*

<a href="https://apryse.com/capabilities#DigitalSignature" class="button primary">Package: Digital Signature</a><a href="https://showcase.apryse.com/digital-signatures" class="button primary">Live demo</a>
{% endhint %}

To sign an existing approval signature field in a PDF Document:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
using (PDFDoc doc = new PDFDoc(docpath))
{
  // Retrieve the unsigned approval signature field.
  Field found_approval_field = doc.GetField(approval_field_name);
  DigitalSignatureField approval_digsig_field = new DigitalSignatureField(found_approval_field);

  // (OPTIONAL) Add more information to the signature dictionary.
  approval_digsig_field.SetLocation("Vancouver, BC");
  approval_digsig_field.SetReason("Document approval.");
  approval_digsig_field.SetContactInfo("www.apryse.com");

  // (OPTIONAL) Add an appearance to the signature field.
  Image img = Image.Create(doc, appearance_img_path);
  SignatureWidget approval_signature_widget = new SignatureWidget(found_approval_field.GetSDFObj());
  approval_signature_widget.CreateSignatureAppearance(img);

  // Prepare the signature and signature handler for signing.
  approval_digsig_field.SignOnNextSave(private_key_file_path, keyfile_password);

  // The actual approval signing will be done during the following incremental save operation.
  doc.Save(outpath, SDFDoc.SaveOptions.e_incremental);
}
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
PDFDoc doc(docpath);

// Retrieve the unsigned approval signature field.
Field found_approval_field(doc.GetField(approval_field_name));
PDF::DigitalSignatureField approval_digsig_field(found_approval_field);

// (OPTIONAL) Add more information to the signature dictionary.
approval_digsig_field.SetLocation("Vancouver, BC");
approval_digsig_field.SetReason("Document approval.");
approval_digsig_field.SetContactInfo("www.apryse.com");

// (OPTIONAL) Add an appearance to the signature field.
PDF::Image img = PDF::Image::Create(doc, appearance_img_path);
Annots::SignatureWidget approval_signature_widget(found_approval_field.GetSDFObj());
approval_signature_widget.CreateSignatureAppearance(img);

// Prepare the signature and signature handler for signing.
approval_digsig_field.SignOnNextSave(private_key_file_path, keyfile_password);

// The actual approval signing will be done during the following incremental save operation.
doc.Save(outpath, SDFDoc::e_incremental, NULL);
```

{% endcode %}
{% endtab %}

{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
doc := NewPDFDoc(docpath)

// Retrieve the unsigned approval signature field.
foundApprovalField := doc.GetField(inApprovalFieldName)
foundApprovalSignatureDigsigField := NewDigitalSignatureField(foundApprovalField)

// (OPTIONAL) Add more information to the signature dictionary.
foundApprovalSignatureDigsigField.SetLocation("Vancouver, BC")
foundApprovalSignatureDigsigField.SetReason("Document approval.")
foundApprovalSignatureDigsigField.SetContactInfo("www.apryse.com")

// (OPTIONAL) Add an appearance to the signature field.
img := ImageCreate(doc.GetSDFDoc(), inAppearanceImgPath)
foundApprovalSignatureWidget := NewSignatureWidget(foundApprovalField.GetSDFObj())
foundApprovalSignatureWidget.CreateSignatureAppearance(img)

// Prepare the signature and signature handler for signing.
foundApprovalSignatureDigsigField.SignOnNextSave(inPrivateKeyFilePath, inKeyfilePassword)

// The actual approval signing will be done during the following incremental save operation.
doc.Save(inOutpath, uint(SDFDocE_incremental))
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
PDFDoc doc = new PDFDoc(docpath);

// Retrieve the unsigned approval signature field.
Field found_approval_field = doc.getField(approval_field_name);
DigitalSignatureField approval_digsig_field = new DigitalSignatureField(found_approval_field);

// (OPTIONAL) Add more information to the signature dictionary.
approval_digsig_field.setLocation("Vancouver, BC");
approval_digsig_field.setReason("Document approval.");
approval_digsig_field.setContactInfo("www.apryse.com");

// (OPTIONAL) Add an appearance to the signature field.
Image img = Image.create(doc, appearance_img_path);
SignatureWidget approval_signature_widget = new SignatureWidget(found_approval_field.getSDFObj());
approval_signature_widget.createSignatureAppearance(img);

// Prepare the signature and signature handler for signing.
approval_digsig_field.signOnNextSave(private_key_file_path, keyfile_password);

// The actual approval signing will be done during the following incremental save operation.
doc.save(outpath, SDFDoc.SaveMode.INCREMENTAL, null);
```

{% endcode %}
{% endtab %}

{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
async function main() {
  const doc = await PDFNet.PDFDoc.createFromFilePath(in_docpath);

  // Retrieve the unsigned approval signature field.
  const found_approval_field = await doc.getField(in_approval_field_name);
  const found_approval_signature_digsig_field = await PDFNet.DigitalSignatureField.createFromField(found_approval_field);

  // (OPTIONAL) Add more information to the signature dictionary.
  await found_approval_signature_digsig_field.setLocation('Vancouver, BC');
  await found_approval_signature_digsig_field.setReason('Document certification.');
  await found_approval_signature_digsig_field.setContactInfo('www.apryse.com');

  // (OPTIONAL) Add an appearance to the signature field.
  const img = await PDFNet.Image.createFromFile(doc, in_appearance_img_path);
  const found_approval_signature_widget = await PDFNet.SignatureWidget.createFromObj(await found_approval_field.getSDFObj());
  await found_approval_signature_widget.createSignatureAppearance(img);

  // Prepare the signature and signature handler for signing.
  await found_approval_signature_digsig_field.signOnNextSave(in_private_key_file_path, in_keyfile_password);

  // The actual approval signing will be done during the following incremental save operation.
  await doc.save(in_outpath, PDFNet.SDFDoc.SaveOptions.e_incremental);
}
PDFNet.runWithCleanup(main);
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
val doc = PDFDoc(docpath)

// Retrieve the unsigned approval signature field.
val found_approval_field = doc.getField(approval_field_name)
val approval_digsig_field = DigitalSignatureField(found_approval_field)

// (OPTIONAL) Add more information to the signature dictionary.
approval_digsig_field.location = "Vancouver, BC"
approval_digsig_field.reason = "Document approval."
approval_digsig_field.contactInfo = "www.apryse.com"

// (OPTIONAL) Add an appearance to the signature field.
val img = Image.create(doc, appearance_img_path)
val approval_signature_widget = SignatureWidget(found_approval_field.sdfObj)
approval_signature_widget.createSignatureAppearance(img)

// Prepare the signature and signature handler for signing.
approval_digsig_field.signOnNextSave(private_key_file_path, keyfile_password)

// The actual approval signing will be done during the following incremental save operation.
doc.save(outpath, SDFDoc.SaveMode.INCREMENTAL, null)
```

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
PTPDFDoc* doc = [[PTPDFDoc alloc] initWithFilepath: docpath];

// Retrieve the unsigned approval signature field.
PTField* found_approval_field = [doc GetField: approval_field_name];
PTDigitalSignatureField* approval_digsig_field = [[PTDigitalSignatureField alloc] initWithIn_field: found_approval_field];

// (OPTIONAL) Add more information to the signature dictionary.
[approval_digsig_field SetLocation: @"Vancouver, BC"];
[approval_digsig_field SetReason: @"Document approval."];
[approval_digsig_field SetContactInfo: @"www.apryse.com"];

// (OPTIONAL) Add an appearance to the signature field.
PTImage* img = [PTImage CreateWithFile: [doc GetSDFDoc] filename: appearance_img_path encoder_hints: [[PTObj alloc]init]];
PTSignatureWidget* approval_signature_widget = [[PTSignatureWidget alloc] initWithD: [found_approval_field GetSDFObj]];
[approval_signature_widget CreateSignatureAppearance: img];

// Prepare the signature and signature handler for signing.
[approval_digsig_field SignOnNextSave: private_key_file_path in_password: keyfile_password];

// The actual approval signing will be done during the following incremental save operation.
[doc SaveToFile: outpath flags: e_ptincremental];
```

{% endcode %}
{% endtab %}

{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
let doc: PTPDFDoc = PTPDFDoc(filepath: in_docpath)

// Retrieve the unsigned approval signature field.
let found_approval_field: PTField = doc.getField(in_approval_field_name)
let found_approval_signature_digsig_field: PTDigitalSignatureField = PTDigitalSignatureField(in_field: found_approval_field)

// (OPTIONAL) Add more information to the signature dictionary.
found_approval_signature_digsig_field.setLocation("Vancouver, BC")
found_approval_signature_digsig_field.setReason("Document certification.")
found_approval_signature_digsig_field.setContactInfo("www.apryse.com")

// (OPTIONAL) Add an appearance to the signature field.
let img: PTImage = PTImage.create(withFile: doc.getSDFDoc(), filename: in_appearance_img_path, encoder_hints: PTObj())
let found_approval_signature_widget: PTSignatureWidget = PTSignatureWidget(d: found_approval_field.getSDFObj())
found_approval_signature_widget.createSignatureAppearance(img)

// Prepare the signature and signature handler for signing.
found_approval_signature_digsig_field.sign(onNextSave: in_private_key_file_path, in_password: in_keyfile_password)

// The actual approval signing will be done during the following incremental save operation.
doc.save(toFile: in_outpath, flags: e_ptincremental.rawValue)
```

{% endcode %}
{% endtab %}

{% tab title="PHP" %}
{% code lineNumbers="true" %}

```php
$doc = new PDFDoc($docpath);

// Retrieve the unsigned approval signature field.
$found_approval_field = $doc->GetField($approval_field_name);
$approval_digsig_field = new DigitalSignatureField($found_approval_field);

// (OPTIONAL) Add more information to the signature dictionary.
$approval_digsig_field->SetLocation('Vancouver, BC');
$approval_digsig_field->SetReason('Document approval.');
$approval_digsig_field->SetContactInfo('www.apryse.com');

// (OPTIONAL) Add an appearance to the signature field.
$img = Image::Create($doc->GetSDFDoc(), $appearance_img_path);
$found_approval_signature_widget = new SignatureWidget($found_approval_field->GetSDFObj());
$found_approval_signature_widget->CreateSignatureAppearance($img);

// Prepare the signature and signature handler for signing.
$approval_digsig_field->SignOnNextSave($private_key_file_path, $keyfile_password);

// The actual approval signing will be done during the following incremental save operation.
$doc->Save($outpath, SDFDoc::e_incremental);
```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
doc = PDFDoc(docpath)

# Retrieve the unsigned approval signature field.
found_approval_field = doc.GetField(approval_field_name)
approval_digsig_field = DigitalSignatureField(found_approval_field)

# (OPTIONAL) Add more information to the signature dictionary.
approval_digsig_field.SetLocation('Vancouver, BC')
approval_digsig_field.SetReason('Document approval.')
approval_digsig_field.SetContactInfo('www.apryse.com')

# (OPTIONAL) Add an appearance to the signature field.
img = Image.Create(doc.GetSDFDoc(), appearance_img_path)
found_approval_signature_widget = SignatureWidget(found_approval_field.GetSDFObj())
found_approval_signature_widget.CreateSignatureAppearance(img)

# Prepare the signature and signature handler for signing.
approval_digsig_field.SignOnNextSave(private_key_file_path, keyfile_password)

# The actual approval signing will be done during the following incremental save operation.
doc.Save(outpath, SDFDoc.e_incremental)
```

{% endcode %}
{% endtab %}

{% tab title="Ruby" %}
{% code lineNumbers="true" %}

```ruby
doc = PDFDoc.new(docpath);

# Retrieve the unsigned approval signature field.
found_approval_field = doc.GetField(approval_field_name);
approval_digsig_field = DigitalSignatureField.new(found_approval_field);

# (OPTIONAL) Add more information to the signature dictionary.
approval_digsig_field.SetLocation('Vancouver, BC');
approval_digsig_field.SetReason('Document approval.');
approval_digsig_field.SetContactInfo('www.apryse.com');

# (OPTIONAL) Add an appearance to the signature field.
img = Image.Create(doc.GetSDFDoc, appearance_img_path);
found_approval_signature_widget = SignatureWidget.new(found_approval_field.GetSDFObj());
found_approval_signature_widget.CreateSignatureAppearance(img);

# Prepare the signature and signature handler for signing.
approval_digsig_field.SignOnNextSave(private_key_file_path, keyfile_password);

# The actual approval signing will be done during the following incremental save operation.
doc.Save(outpath, SDFDoc::E_incremental);
```

{% endcode %}
{% endtab %}

{% tab title="VB" %}
{% code lineNumbers="true" %}

```vb
Using doc As PDFDoc = New PDFDoc(docpath)
  ' Retrieve the unsigned approval signature field.
  Dim found_approval_field As Field = doc.GetField(approval_field_name)
  Dim approval_digsig_field As DigitalSignatureField = New DigitalSignatureField(found_approval_field)
  Dim img As Image = Image.Create(doc, appearance_img_path)

  ' (OPTIONAL) Add more information to the signature dictionary.
  approval_digsig_field.SetLocation("Vancouver, BC")
  approval_digsig_field.SetReason("Document approval.")
  approval_digsig_field.SetContactInfo("www.apryse.com")

  ' (OPTIONAL) Add an appearance to the signature field.
  Dim found_approval_signature_widget As SignatureWidget = New SignatureWidget(found_approval_field.GetSDFObj())
  found_approval_signature_widget.CreateSignatureAppearance(img)

  ' Prepare the signature and signature handler for signing.
  approval_digsig_field.SignOnNextSave(private_key_file_path, keyfile_password)

  ' The actual approval signing will be done during the following incremental save operation.
  doc.Save(in_outpath, SDFDoc.SaveOptions.e_incremental)
End Using
```

{% endcode %}
{% endtab %}
{% endtabs %}

[Digitally sign PDF files](/core/get-started/samples/digitalsignaturestest.md) Full code sample which demonstrates using the digital signature API to digitally sign and/or certify PDF documents. Code sample is available in C++, C#, Java, Python, Go, PHP, Ruby & VB.

## About Adding An Approval Signature to a PDF Document

The Apryse SDK enables approval signatures in PDF documents using a Digital Certificate, in accordance with the latest PDF specification. By leveraging [public key infrastructure (PKI)](https://en.wikipedia.org/wiki/Public_key_infrastructure) technology, with a certificate issued by a trusted [certificate authority (CA)](https://en.wikipedia.org/wiki/Certificate_authority), a signer can use a certificate-based digital ID to guarantee the authenticity of a signature. Placement of a digital signature using a certificate can also guarantee that a document was not modified since the signature was placed, ensuring the authenticity of the document.

![](https://3779731113-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fziw3GiL98Xfj63F3He8h%2Fuploads%2Fgit-blob-51c4b698c1ec2efcc0d46686d1342347626f1a9d%2F8130e2be0155c3a56bbf8548f836090a8beb0ac2-299x658.png?alt=media)

Image taken from Apryse WebViewer

Above is an example of a document containing a certified signature, guaranteed by a certificate generated by Apryse.com.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/core/digital-signature/sign-pdf.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
