> 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/smart-data-extraction/kve.md).

# Key Value Extraction

Apryse's Key-Value Extraction engine helps you automatically identify and extract meaningful key-value pairs from PDFs, part of the Apryse Server SDK Smart Data Extraction offering.

{% 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#SmartDataExtraction" class="button primary">Package: Smart Data Extraction</a><a href="/core/learn-more/modules.md#data-extraction-module" class="button primary">Module: Data Extraction</a><a href="https://showcase.apryse.com/key-value-extraction" class="button primary">Live demo</a>
{% endhint %}

Apryse's Key-Value Extraction engine helps you automatically identify and extract meaningful key-value pairs from PDFs — even when the document is unstructured or doesn't contain form fields. Whether you're processing invoices, resumes, or complex reports, KVE saves hours of manual tagging by turning documents into structured JSON.

{% hint style="info" %}
**NEW FEATURE**

New in 11.8!
{% endhint %}

Exclusive to the Apryse SDK, Key-Value Extraction also supports pulling data from CAD and other technical drawing title blocks.

### How It Works

The engine scans each page for likely key terms (e.g., labels, field names, categories) and maps them to associated values (e.g., specific data, answers, identifiers). This hyponymic relationship allows KVE to structure data from real-world documents without templates or prior annotation.

### JSON Output Specification

Refer to the following specifications to learn more about the output JSON format:

* [JSON Specification for Generic Key-Value Extraction](https://sdk.apryse.com/api/keyvalueextractjson/modules.html)

### Extract key-value pairs as JSON file

Specify the name of the input PDF file and the name of the output JSON file, then select the Generic Key Value engine:

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

```csharp
DataExtractionModule.ExtractData("newsletter.pdf", "newsletter.json", DataExtractionModule.DataExtractionEngine.e_generic_key_value);
```

{% endcode %}
{% endtab %}

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

```cpp
DataExtractionModule::ExtractData("newsletter.pdf", "newsletter.json", DataExtractionModule::e_GenericKeyValue);
```

{% endcode %}
{% endtab %}

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

```go
DataExtractionModuleExtractData("newsletter.pdf", "newsletter.json", DataExtractionModuleE_GenericKeyValue)
```

{% endcode %}
{% endtab %}

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

```java
DataExtractionModule.extractData("newsletter.pdf", "newsletter.json", DataExtractionModule.DataExtractionEngine.e_generic_key_value);
```

{% endcode %}
{% endtab %}

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

```js
await PDFNet.DataExtractionModule.extractData("newsletter.pdf", "newsletter.json", PDFNet.DataExtractionModule.DataExtractionEngine.e_GenericKeyValue);
```

{% endcode %}
{% endtab %}

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

```php
DataExtractionModule::ExtractData("newsletter.pdf", "newsletter.json", DataExtractionModule::e_GenericKeyValue);
```

{% endcode %}
{% endtab %}

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

```python
DataExtractionModule.ExtractData("newsletter.pdf", "newsletter.json", DataExtractionModule.e_GenericKeyValue)
```

{% endcode %}
{% endtab %}

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

```ruby
DataExtractionModule.ExtractData("newsletter.pdf", "newsletter.json", DataExtractionModule::E_GenericKeyValue)
```

{% endcode %}
{% endtab %}

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

```vb
DataExtractionModule.ExtractData("newsletter.pdf", "newsletter.json", DataExtractionModule.DataExtractionEngine.e_generic_key_value)
```

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

### Extract key-value pairs as JSON string

Specify the name of the input PDF file, then select the Generic Key Value engine:

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

```csharp
string json = DataExtractionModule.ExtractData("newsletter.pdf", DataExtractionModule.DataExtractionEngine.e_generic_key_value);
```

{% endcode %}
{% endtab %}

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

```cpp
UString json = DataExtractionModule::ExtractData("newsletter.pdf", DataExtractionModule::e_GenericKeyValue);
```

{% endcode %}
{% endtab %}

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

```go
json := DataExtractionModuleExtractData("newsletter.pdf", DataExtractionModuleE_GenericKeyValue).(string)
```

{% endcode %}
{% endtab %}

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

```java
String json = DataExtractionModule.extractData("newsletter.pdf", DataExtractionModule.DataExtractionEngine.e_generic_key_value);
```

{% endcode %}
{% endtab %}

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

```js
const json = await PDFNet.DataExtractionModule.extractDataAsString('newsletter.pdf', PDFNet.DataExtractionModule.DataExtractionEngine.e_GenericKeyValue);
```

{% endcode %}
{% endtab %}

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

```php
$json = DataExtractionModule::ExtractData("newsletter.pdf", DataExtractionModule::e_GenericKeyValue);
```

{% endcode %}
{% endtab %}

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

```python
json = DataExtractionModule.ExtractData("newsletter.pdf", DataExtractionModule.e_GenericKeyValue)
```

{% endcode %}
{% endtab %}

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

```ruby
json = DataExtractionModule.ExtractData("newsletter.pdf", DataExtractionModule::E_GenericKeyValue)
```

{% endcode %}
{% endtab %}

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

```vb
Dim json As String = DataExtractionModule.ExtractData("newsletter.pdf", DataExtractionModule.DataExtractionEngine.e_generic_key_value)
```

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

### Optional Configurations

[Select OCR Language](/core/smart-data-extraction/workflow.md#select-ocr-language)

[Password-Protected PDFs](/core/smart-data-extraction/workflow.md#specify-pdf-password)

[Page Range](/core/smart-data-extraction/workflow.md#select-a-page-range)

[Region of Interest](/core/smart-data-extraction/workflow.md#specify-regions-of-interest)

[Detect Empty Fields](/core/smart-data-extraction/workflow.md#detect-empty-fields)

### Use Key-Value Extraction engine with DetectAndAddFormFieldsToPDF

By default, `DetectAndAddFormFieldsToPDF` uses the [Form Field Detection engine](/core/smart-data-extraction/form-field.md#form-field-detection-engine). You can force the function to use the [Form Field Key-Value Extraction engine](/core/smart-data-extraction/form-field.md#form-field-key-value-extraction-engine) using the "Form Extraction Engine" option.

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

```csharp
PDFDoc doc = new PDFDoc("formfields.pdf");
DataExtractionOptions options = new DataExtractionOptions();
options.SetFormExtractionEngine("FormKeyValue");
DataExtractionModule.DetectAndAddFormFieldsToPDF(doc, options);
```

{% endcode %}
{% endtab %}

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

```cpp
PDFDoc doc("formfields.pdf");
DataExtractionOptions options;
options.SetFormExtractionEngine("FormKeyValue");
DataExtractionModule::DetectAndAddFormFieldsToPDF(doc, &options);
```

{% endcode %}
{% endtab %}

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

```go
doc = NewPDFDoc("formfields.pdf")
options := NewDataExtractionOptions()
options.SetFormExtractionEngine("FormKeyValue")
DataExtractionModuleDetectAndAddFormFieldsToPDF(doc, options)
```

{% endcode %}
{% endtab %}

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

```java
PDFDoc doc = new PDFDoc("formfields.pdf");
DataExtractionOptions options = new DataExtractionOptions();
options.setFormExtractionEngine("FormKeyValue");
DataExtractionModule.detectAndAddFormFieldsToPDF(doc, options);
```

{% endcode %}
{% endtab %}

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

```js
const doc = await PDFNet.PDFDoc.createFromFilePath("formfields.pdf");
const options = new PDFNet.DataExtractionModule.DataExtractionOptions();
options.setFormExtractionEngine('FormKeyValue');
await PDFNet.DataExtractionModule.detectAndAddFormFieldsToPDF(doc, options);
```

{% endcode %}
{% endtab %}

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

```php
$doc = new PDFDoc("formfields.pdf");
$options = new DataExtractionOptions();
$options->SetFormExtractionEngine("FormKeyValue");
DataExtractionModule::DetectAndAddFormFieldsToPDF($doc, $options);
```

{% endcode %}
{% endtab %}

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

```python
doc = PDFDoc("formfields.pdf")
options = DataExtractionOptions()
options.SetFormExtractionEngine("FormKeyValue")
DataExtractionModule.DetectAndAddFormFieldsToPDF(doc, options)
```

{% endcode %}
{% endtab %}

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

```ruby
doc = PDFDoc.new("formfields.pdf")
options = DataExtractionOptions.new()
options.SetFormExtractionEngine("FormKeyValue")
DataExtractionModule.DetectAndAddFormFieldsToPDF(doc, options)
```

{% endcode %}
{% endtab %}

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

```vb
Dim doc as PDFDoc = New PDFDoc("formfields.pdf")
Dim options = New DataExtractionOptions()
options.SetFormExtractionEngine("FormKeyValue")
DataExtractionModule.DetectAndAddFormFieldsToPDF(doc, options)
```

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

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

This option only has an effect on the \`DetectAndAddFormFieldsToPDF\` function. Passing this option to \`ExtractData\` will have no effect, as the \`engine\` parameter will take precedence.
{% endhint %}


---

# 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/smart-data-extraction/kve.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.
