> 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/document-structure.md).

# Document Structure Recognition

Apryse's Document Structure Recognition engine helps you capture the visual and logical layout of a document. Great for use with Accessibility tagging (e.g., reading order), screen reading tools, docu

{% 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/document-structure-extraction" class="button primary">Live demo</a>
{% endhint %}

## Document Structure Recognition

Apryse's Document Structure Recognition engine helps you capture the visual and logical layout of a document. Unlike tabular extraction, this mode is designed to mimic how a human sees the page — recognizing paragraphs, lists, headers, footers, and images as distinct blocks.

It's ideal for use cases involving:

* Accessibility tagging (e.g., reading order)
* Screen reading tools
* Document reconstruction
* Visual layout parsing

### How It Works

The engine detects layout elements based on visual positioning, spacing, indentation, and structural boundaries. It separates:

* Paragraphs and lists
* Headers and footers
* Section columns vs table columns
* Tables embedded inside paragraphs
* Images and graphical elements

### JSON Output Specification

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

* [JSON Specification for Tabular Data and Document Structure](https://sdk.apryse.com/api/structurejson/index.html)

### Extract document structure as JSON file

Specify the name of the input PDF file and the name of the output JSON file, then select the Doc Structure engine:

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

```csharp
DataExtractionModule.ExtractData("paragraphs_and_tables.pdf", "paragraphs_and_tables.json", DataExtractionModule.DataExtractionEngine.e_doc_structure);
```

{% endcode %}
{% endtab %}

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

```cpp
DataExtractionModule::ExtractData("paragraphs_and_tables.pdf", "paragraphs_and_tables.json", DataExtractionModule::e_DocStructure);
```

{% endcode %}
{% endtab %}

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

```go
DataExtractionModuleExtractData("paragraphs_and_tables.pdf", "paragraphs_and_tables.json", DataExtractionModuleE_DocStructure)
```

{% endcode %}
{% endtab %}

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

```java
DataExtractionModule.extractData("paragraphs_and_tables.pdf", "paragraphs_and_tables.json", DataExtractionModule.DataExtractionEngine.e_doc_structure);
```

{% endcode %}
{% endtab %}

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

```js
await PDFNet.DataExtractionModule.extractData('paragraphs_and_tables.pdf', 'paragraphs_and_tables.json', PDFNet.DataExtractionModule.DataExtractionEngine.e_DocStructure);
```

{% endcode %}
{% endtab %}

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

```php
DataExtractionModule::ExtractData("paragraphs_and_tables.pdf", "paragraphs_and_tables.json", DataExtractionModule::e_DocStructure);
```

{% endcode %}
{% endtab %}

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

```python
DataExtractionModule.ExtractData("paragraphs_and_tables.pdf", "paragraphs_and_tables.json", DataExtractionModule.e_DocStructure)
```

{% endcode %}
{% endtab %}

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

```ruby
DataExtractionModule.ExtractData("paragraphs_and_tables.pdf", "paragraphs_and_tables.json", DataExtractionModule::E_DocStructure)
```

{% endcode %}
{% endtab %}

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

```vb
DataExtractionModule.ExtractData("paragraphs_and_tables.pdf", "paragraphs_and_tables.json", DataExtractionModule.DataExtractionEngine.e_doc_structure)
```

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

### Extract document structure as JSON string

If you are going to parse the JSON right away, you may as well retrieve it as an in-memory string, instead of an external file.

Specify the name of the input PDF file, then select the Doc Structure engine:

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

```csharp
string json = DataExtractionModule.ExtractData("tagged.pdf", DataExtractionModule.DataExtractionEngine.e_doc_structure);
```

{% endcode %}
{% endtab %}

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

```cpp
UString json = DataExtractionModule::ExtractData("tagged.pdf", DataExtractionModule::e_DocStructure);
```

{% endcode %}
{% endtab %}

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

```go
json := DataExtractionModuleExtractData("tagged.pdf", DataExtractionModuleE_DocStructure).(string)
```

{% endcode %}
{% endtab %}

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

```java
String json = DataExtractionModule.extractData("tagged.pdf", DataExtractionModule.DataExtractionEngine.e_doc_structure);
```

{% endcode %}
{% endtab %}

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

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

{% endcode %}
{% endtab %}

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

```php
$json = DataExtractionModule::ExtractData("tagged.pdf", DataExtractionModule::e_DocStructure);
```

{% endcode %}
{% endtab %}

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

```python
json = DataExtractionModule.ExtractData("tagged.pdf", DataExtractionModule.e_DocStructure)
```

{% endcode %}
{% endtab %}

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

```ruby
json = DataExtractionModule.ExtractData("tagged.pdf", DataExtractionModule::E_DocStructure)
```

{% endcode %}
{% endtab %}

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

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

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

### Extract document structure as a Markdown file

In addition to JSON, document structure can be extracted directly to Markdown — useful for feeding document content into LLMs, static site generators, or any Markdown-based pipeline.

Specify the name of the input PDF file and the name of the output Markdown file:

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

```csharp
DataExtractionModule.ExtractToMarkdown("paragraphs_and_tables.pdf", "paragraphs_and_tables.md");
```

{% endcode %}
{% endtab %}

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

```cpp
DataExtractionModule::ExtractToMarkdown("paragraphs_and_tables.pdf", "paragraphs_and_tables.md");
```

{% endcode %}
{% endtab %}

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

```go
DataExtractionModuleExtractToMarkdown("paragraphs_and_tables.pdf", "paragraphs_and_tables.md")
```

{% endcode %}
{% endtab %}

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

```java
DataExtractionModule.extractToMarkdown("paragraphs_and_tables.pdf", "paragraphs_and_tables.md");
```

{% endcode %}
{% endtab %}

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

```php
DataExtractionModule::ExtractToMarkdown("paragraphs_and_tables.pdf", "paragraphs_and_tables.md");
```

{% endcode %}
{% endtab %}

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

```python
DataExtractionModule.ExtractToMarkdown("paragraphs_and_tables.pdf", "paragraphs_and_tables.md")
```

{% endcode %}
{% endtab %}

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

```ruby
DataExtractionModule.ExtractToMarkdown("paragraphs_and_tables.pdf", "paragraphs_and_tables.md")
```

{% endcode %}
{% endtab %}

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

```vb
DataExtractionModule.ExtractToMarkdown("paragraphs_and_tables.pdf", "paragraphs_and_tables.md")
```

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

### **Extract document structure using the Paddle OCR engine**

For scanned or image-based PDFs, you can choose the Paddle OCR engine for improved accuracy on low-quality scans and complex layouts. See [Select OCR Engine](/core/smart-data-extraction/workflow.md#select-ocr-engine) for a full comparison of the two engines. Since Paddle does not support automatic language detection, the OCR language must be set explicitly.

The following example shows how to extract document structure as a Markdown file using the Paddle OCR engine.

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

Paddle OCR is currently available in the Windows x64 and Linux x64 builds of the Data Extraction Module.
{% endhint %}

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

```csharp
DataExtractionOptions options = new DataExtractionOptions();
options.SetLanguage("eng");
options.SetPreferredOCREngine(DataExtractionOptions.DataExtractionOCREngine.e_extract_ocr_paddle);
DataExtractionModule.ExtractToMarkdown("scanned.pdf", "scanned.md", options);
```

{% endcode %}
{% endtab %}

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

```cpp
DataExtractionOptions options;
options.SetLanguage("eng");
options.SetPreferredOCREngine(DataExtractionOptions::e_extract_ocr_paddle);
DataExtractionModule::ExtractToMarkdown("scanned.pdf", "scanned.md", &options);
```

{% endcode %}
{% endtab %}

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

```go
options := NewDataExtractionOptions()
options.SetLanguage("eng")
options.SetPreferredOCREngine(DataExtractionOptionsE_extract_ocr_paddle)
DataExtractionModuleExtractToMarkdown("scanned.pdf", "scanned.md", options)
```

{% endcode %}
{% endtab %}

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

```java
DataExtractionOptions options = new DataExtractionOptions();
options.setLanguage("eng");
options.setPreferredOCREngine(DataExtractionOptions.DataExtractionOCREngine.e_extract_ocr_paddle);
DataExtractionModule.extractToMarkdown("scanned.pdf", "scanned.md", options);
```

{% endcode %}
{% endtab %}

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

```php
$options = new DataExtractionOptions();
$options->SetLanguage("eng");
$options->SetPreferredOCREngine(DataExtractionOptions::e_extract_ocr_paddle);
DataExtractionModule::ExtractToMarkdown("scanned.pdf", "scanned.md", $options);
```

{% endcode %}
{% endtab %}

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

```python
options = DataExtractionOptions()
options.SetLanguage("eng")
options.SetPreferredOCREngine(DataExtractionOptions.e_extract_ocr_paddle)
DataExtractionModule.ExtractToMarkdown("scanned.pdf", "scanned.md", options)
```

{% endcode %}
{% endtab %}

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

```ruby
options = DataExtractionOptions.new()
options.SetLanguage("eng")
options.SetPreferredOCREngine(DataExtractionOptions::E_extract_ocr_paddle)
DataExtractionModule.ExtractToMarkdown("scanned.pdf", "scanned.md", options)
```

{% endcode %}
{% endtab %}

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

```vb
Dim options As DataExtractionOptions = New DataExtractionOptions()
options.SetLanguage("eng")
options.SetPreferredOCREngine(DataExtractionOptions.DataExtractionOCREngine.e_extract_ocr_paddle)
DataExtractionModule.ExtractToMarkdown("scanned.pdf", "scanned.md", options)
```

{% 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)
* [Deep Learning Assist](/core/smart-data-extraction/workflow.md#deep-learning-assist)


---

# 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 following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/core/smart-data-extraction/document-structure.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

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.
