> 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/annotation/export.md).

# Export annotations on Server/Desktop

Learn how to extract data from PDF to FDF and export FDF as XFDF with full sample code for PDF Form Fill and Data Extraction. Complete support for FDF merge/extract functionality. The Apryse Server SD

To extract data from PDF to FDF, then export FDF as XFDF

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

```csharp
PDFDoc doc = new PDFDoc(filename);

// Extract annotations to FDF.
// Optionally use e_both to extract both forms and annotations
FDFDoc doc_fields = doc.FDFExtract(PDFDoc.ExtractFlag.e_annots_only); //PDFDoc.ExtractFlag.e_forms_only

// Export annotations from FDF to XFDF.
doc_fields.SaveAsXFDF(output_xfdf_filename);

// Optionally write XFDF to a string
string XFDF_string = doc_fields.SaveAsXFDF();
```

{% endcode %}
{% endtab %}

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

```cpp
PDFDoc doc(filename);

// Extract annotations to FDF.
// Optionally use e_both to extract both forms and annotations
FDFDoc doc_fields = doc.FDFExtract(PDFDoc::e_annots_only); //PDFDoc::e_forms_only

// Export annotations from FDF to XFDF.
doc_fields.SaveAsXFDF(output_xfdf_filename);

// Optionally write XFDF to a string
UString XFDF_string = doc_fields.SaveAsXFDF();
```

{% endcode %}
{% endtab %}

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

```go
doc := NewPDFDoc(filename)

// Extract annotations to FDF.
// Optionally use e_both to extract both forms and annotations
docFields := inDoc.FDFExtract(PDFDocE_annots_only) // PDFDocE_forms_only

// Export annotations from FDF to XFDF.
docFields.SaveAsXFDF(output_xfdf_filename)

// Optionally write XFDF to a string
xfdfStr := docFields.SaveAsXFDF()
```

{% endcode %}
{% endtab %}

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

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

// Extract annotations to FDF.
// Optionally use e_both to extract both forms and annotations
FDFDoc doc_fields = doc.fdfExtract(PDFDoc.e_annots_only); //PDFDoc.e_forms_only

// Export annotations from FDF to XFDF.
doc_fields.saveAsXFDF(output_xfdf_filename);

// Optionally write XFDF to a string
String XFDF_string = doc_fields.saveAsXFDF();
```

{% endcode %}
{% endtab %}

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

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

  // Extract annotations to FDF.
  // Optionally use e_both to extract both forms and annotations
  const doc_fields = await doc.fdfExtract(PDFNet.PDFDoc.ExtractFlag.e_annots_only); //PDFNet.PDFDoc.ExtractFlag.e_forms_only

  // Export annotations from FDF to XFDF.
  const xfdf_data = await doc_fields.saveAsXFDFAsString();

  //optionally save the blob to a file or upload to a server
  const blob = new Blob([xfdf_data], { type: 'application/xml' });
}
PDFNet.runWithCleanup(main);
```

{% endcode %}

[PDFNet.PDFDoc.createFromURL](https://sdk.apryse.com/api/web/Core.PDFNet.PDFDoc.html#.createFromURL__anchor) [PDFNet.PDFDoc.fdfExtract](https://sdk.apryse.com/api/web/Core.PDFNet.PDFDoc.html#fdfExtract__anchor) [PDFNet.FDFDoc.saveAsXFDFAsString](https://sdk.apryse.com/api/web/Core.PDFNet.FDFDoc.html#saveAsXFDFAsString__anchor)
{% endtab %}

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

```kotlin
val doc = PDFDoc(filename)

// Extract annotations to FDF.
// Optionally use e_both to extract both forms and annotations
val doc_fields = doc.fdfExtract(PDFDoc.e_annots_only) //PDFDoc.e_forms_only

// Export annotations from FDF to XFDF.
doc_fields.saveAsXFDF(output_xfdf_filename)

// Optionally write XFDF to a string
val XFDF_string = doc_fields.saveAsXFDF()
```

{% endcode %}
{% endtab %}

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

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

// Extract annotations to FDF.
// Optionally use e_ptboth to extract both forms and annotations
PTFDFDoc *doc_fields = [doc FDFExtract: e_ptannots_only]; //e_ptforms_only

// Export annotations from FDF to XFDF.
[doc_fields SaveAsXFDF: output_xfdf_filename];

// Optionally write XFDF to a string
NSString *XFDF_string = [doc_fields SaveAsXFDFToString];
```

{% endcode %}
{% endtab %}

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

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

// Extract annotations to FDF.
// Optionally use e_ptboth to extract both forms and annotations
let doc_fields: PTFDFDoc = doc.fdfExtract(e_ptannots_only) //e_ptforms_only

// Export annotations from FDF to XFDF.
doc_fields.save(asXFDF: output_xfdf_filename)

// Optionally write XFDF to a string
let XFDF_string: String = doc_fields.saveAsXFDFToString()
```

{% endcode %}
{% endtab %}

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

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

// Extract annotations to FDF.
// Optionally use e_both to extract both forms and annotations
$doc_fields = $doc->FDFExtract(PDFDoc::e_annots_only); //PDFDoc::e_forms_only

// Export annotations from FDF to XFDF.
$doc_fields->SaveAsXFDF($output_xfdf_filename);

// Optionally write XFDF to a string
$XFDF_string = $doc_fields->SaveAsXFDF();
```

{% endcode %}
{% endtab %}

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

```python
doc = PDFDoc(filename)

# Extract annotations to FDF.
# Optionally use e_both to extract both forms and annotations
doc_fields = doc.FDFExtract(PDFDoc.e_annots_only) #PDFDoc.e_forms_only

# Export annotations from FDF to XFDF.
doc_fields.SaveAsXFDF(output_xfdf_filename)

# Optionally write XFDF to a string
XFDF_string = doc_fields.SaveAsXFDF()
```

{% endcode %}
{% endtab %}

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

```ruby
doc = PDFDoc.new(filename)

# Extract annotations to FDF.
# Optionally use e_both to extract both forms and annotations
doc_fields = doc.FDFExtract(PDFDoc::E_annot_only) #PDFDoc::E_forms_only

# Export annotations from FDF to XFDF.
doc_fields.SaveAsXFDF(output_xfdf_filename)

# Optionally write XFDF to a string
XFDF_string = doc_fields.SaveAsXFDF()
```

{% endcode %}
{% endtab %}

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

```vb
Dim doc As PDFDoc = New PDFDoc(filename)

' Extract annotations to FDF.
' Optionally use e_both to extract both forms and annotations
Dim doc_fields As FDFDoc = doc.FDFExtract(PDF.PDFDoc.ExtractFlag.e_annot_only) 'PDF.PDFDoc.ExtractFlag.e_forms_only

' Export annotations from FDF to XFDF.
doc_fields.SaveAsXFDF(output_xfdf_filename)

' Optionally write XFDF to a string
Dim XFDF_string As String = doc_fields.SaveAsXFDF()
```

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

[PDF Form Fill and Form Data Extraction - Full Sample](/core/get-started/samples/fdftest.md) Full sample code which illustrates basic FDF merge/extract functionality and full support for FDF (Forms Data Format). Samples available in Python, C# (.Net), C++, Go, Java, Node.js (JavaScript), PHP, Ruby, VB.


---

# 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/annotation/export.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.
