> 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/conversion/convert-to-office.md).

# Convert PDF to Word, Excel, and PowerPoint for Windows, Linux, and macOS: Sample Code in C#, Python,

Convert PDFs to MS Office (DOCX, XLSX, PPTX) without third-party dependencies. Download the Structured Output Module for PDF to Office conversion on Desktop and Server. Learn how to install and use it

Convert PDFs to MS Office (DOCX, XLSX, PPTX) without any external third party dependencies. PDF to Word, PDF to Excel, PDF to PowerPoint are all provided with support for C#, Python, C++, Java, PHP, Ruby, Go; on Windows, Linux and Mac.

{% hint style="warning" %}
**The Structured Output module is an optional add-on**

Only available on Desktop and Server (Windows, Linux, or Mac) You can find more details about how to install the Structured Output module [here ](/core/learn-more/modules.md#structured-output-module).
{% endhint %}

## Setup

1. Download the [Structured Output Module](/core/learn-more/modules.md#structured-output-module) that allows PDF to Office conversion.
2. Place it in the directory of your project, in a folder called `lib` and then reference it in the below sample.

## Convert PDF to Word

This sample demonstrates how to convert from a PDF to DOCX file.

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

```csharp
Convert.WordOutputOptions wordOutputOptions = new Convert.WordOutputOptions();
// Optionally convert only the first page
wordOutputOptions.SetPages(1, 1);
// Requires the Structured Output module
Convert.ToWord(filename, output_filename, wordOutputOptions);
```

{% endcode %}
{% endtab %}

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

```cpp
Convert::WordOutputOptions wordOutputOptions;
// Optionally convert only the first page
wordOutputOptions.SetPages(1, 1);
// Requires the Structured Output module
Convert::ToWord(filename, output_filename, wordOutputOptions);
```

{% endcode %}
{% endtab %}

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

```go
wordOutputOptions := NewWordOutputOptions()
// Optionally convert only the first page
wordOutputOptions.SetPages(1, 1)
// Requires the Structured Output module
ConvertToWord(filename, output_filename, wordOutputOptions)
```

{% endcode %}
{% endtab %}

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

```java
Convert.WordOutputOptions wordOutputOptions = new Convert.WordOutputOptions();
// Optionally convert only the first page
wordOutputOptions.setPages(1, 1);
// Requires the Structured Output module
Convert.toWord(filename, output_filename, wordOutputOptions);
```

{% endcode %}
{% endtab %}

{% tab title="JavaScript" %}

<pre class="language-js" data-line-numbers><code class="lang-js">const { PDFNet } = require('@pdftron/pdfnet-node');
async function main() {
  await PDFNet.addResourceSearchPath('./lib/');
  // check if the module is available
  if (!(await PDFNet.StructuredOutputModule.isModuleAvailable())) {
    return;
  }
  await PDFNet.Convert.fileToWord('./input.pdf', 'output.docx');
}
PDFNet.runWithCleanup(main, '<code class="expression">visitor.claims.serverKey || "YOUR_LICENSE_KEY"</code>');
</code></pre>

{% endtab %}

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

```php
$wordOutputOptions = new WordOutputOptions();
// Optionally convert only the first page
$wordOutputOptions->SetPages(1, 1);
// Requires the Structured Output module
Convert::ToWord($filename, $output_filename, wordOutputOptions);
```

{% endcode %}
{% endtab %}

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

```python
wordOutputOptions = WordOutputOptions()
# Optionally convert only the first page
wordOutputOptions.SetPages(1, 1)
# Requires the Structured Output module
Convert.ToWord(filename, output_filename, wordOutputOptions)
```

{% endcode %}
{% endtab %}

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

```ruby
$wordOutputOptions = Convert::WordOutputOptions.new()
# Optionally convert only the first page
$wordOutputOptions.SetPages(1, 1);
# Requires the Structured Output module
Convert.toWord(filename, output_filename, $wordOutputOptions)
```

{% endcode %}
{% endtab %}

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

```vb
Dim wordOutputOptions As pdftron.PDF.Convert.WordOutputOptions = New pdftron.PDF.Convert.WordOutputOptions()
' Optionally convert only the first page
wordOutputOptions.SetPages(1, 1)
' Requires the Structured Output module
Convert.ToWord(filename, output_filename, wordOutputOptions)
```

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

## Convert PDF to Word with Paddle OCR

For scanned or image-based PDFs, `SetPreferredOCREngine()` lets you choose the Paddle OCR engine instead of the default engine for improved accuracy on low-quality scans and complex layouts, at the cost of longer processing time (see [Select OCR Engine](/core/smart-data-extraction/workflow.md#select-ocr-engine) for a full comparison). Since Paddle does not support automatic language detection, set the OCR language explicitly with `SetCustomOCRLanguage()`.

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

`SetPreferredOCREngine()` is also available on `ExcelOutputOptions`, `PowerPointOutputOptions`, and `HTMLOutputOptions` (for HTML, only when using `e_reflow_full` mode).
{% endhint %}

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

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

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

```csharp
Convert.WordOutputOptions wordOutputOptions = new Convert.WordOutputOptions();
wordOutputOptions.SetCustomOCRLanguage("eng");
wordOutputOptions.SetPreferredOCREngine(Convert.OutputOptionsOCR.PreferredOCREngine.e_engine_paddle);
Convert.ToWord(filename, output_filename, wordOutputOptions);
```

{% endcode %}
{% endtab %}

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

```cpp
Convert::WordOutputOptions wordOutputOptions;
wordOutputOptions.SetCustomOCRLanguage("eng");
wordOutputOptions.SetPreferredOCREngine(Convert::OutputOptionsOCR::e_engine_paddle);
Convert::ToWord(filename, output_filename, wordOutputOptions);
```

{% endcode %}
{% endtab %}

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

```go
wordOutputOptions := NewWordOutputOptions()
wordOutputOptions.SetCustomOCRLanguage("eng")
wordOutputOptions.SetPreferredOCREngine(OutputOptionsOCRE_engine_paddle)
ConvertToWord(filename, output_filename, wordOutputOptions)
```

{% endcode %}
{% endtab %}

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

```java
Convert.WordOutputOptions wordOutputOptions = new Convert.WordOutputOptions();
wordOutputOptions.setCustomOCRLanguage("eng");
wordOutputOptions.setPreferredOCREngine(Convert.OutputOptionsOCR.PreferredOCREngine.e_engine_paddle);
Convert.toWord(filename, output_filename, wordOutputOptions);
```

{% endcode %}
{% endtab %}

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

```php
$wordOutputOptions = new WordOutputOptions();
$wordOutputOptions->SetCustomOCRLanguage("eng");
$wordOutputOptions->SetPreferredOCREngine(OutputOptionsOCR::e_engine_paddle);
Convert::ToWord($filename, $output_filename, $wordOutputOptions);
```

{% endcode %}
{% endtab %}

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

```python
wordOutputOptions = WordOutputOptions()
wordOutputOptions.SetCustomOCRLanguage("eng")
wordOutputOptions.SetPreferredOCREngine(OutputOptionsOCR.e_engine_paddle)
Convert.ToWord(filename, output_filename, wordOutputOptions)
```

{% endcode %}
{% endtab %}

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

```ruby
$wordOutputOptions = Convert::WordOutputOptions.new()
$wordOutputOptions.SetCustomOCRLanguage("eng")
$wordOutputOptions.SetPreferredOCREngine(OutputOptionsOCR::E_engine_paddle)
Convert.toWord(filename, output_filename, $wordOutputOptions)
```

{% endcode %}
{% endtab %}

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

```vb
Dim wordOutputOptions As pdftron.PDF.Convert.WordOutputOptions = New pdftron.PDF.Convert.WordOutputOptions()
wordOutputOptions.SetCustomOCRLanguage("eng")
wordOutputOptions.SetPreferredOCREngine(pdftron.PDF.Convert.OutputOptionsOCR.PreferredOCREngine.e_engine_paddle)
Convert.ToWord(filename, output_filename, wordOutputOptions)
```

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

{% hint style="info" %}
**Info-Reducing size when Paddle OCR is not used**

If you don't use the Paddle OCR engine, you can delete the `paddleocr` and `onnx` directories, located directly under `Lib/Windows` (Windows) or `Lib/Linux` (Linux), to reduce package/disk footprint.
{% endhint %}

## Convert PDF to PowerPoint

This sample demonstrates how to convert from a PDF to PPTX file.

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

```csharp
Convert.PowerPointOutputOptions powerPointOutputOptions = new Convert.PowerPointOutputOptions();
// Optionally convert only the first page
powerPointOutputOptions.SetPages(1, 1);
// Requires the Structured Output module
Convert.ToPowerPoint(filename, output_filename, powerPointOutputOptions);
```

{% endcode %}
{% endtab %}

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

```cpp
Convert::PowerPointOutputOptions powerPointOutputOptions;
// Optionally convert only the first page
powerPointOutputOptions.SetPages(1, 1);
// Requires the Structured Output module
Convert::ToPowerPoint(filename, output_filename, powerPointOutputOptions);
```

{% endcode %}
{% endtab %}

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

```go
powerPointOutputOptions := NewPowerPointOutputOptions()
// Optionally convert only the first page
powerPointOutputOptions.SetPages(1, 1)
// Requires the Structured Output module
ConvertToPowerPoint(filename, output_filename, powerPointOutputOptions)
```

{% endcode %}
{% endtab %}

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

```java
Convert.PowerPointOutputOptions powerPointOutputOptions = new Convert.PowerPointOutputOptions();
// Optionally convert only the first page
powerPointOutputOptions.setPages(1, 1);
// Requires the Structured Output module
Convert.toPowerPoint(filename, output_filename, powerPointOutputOptions);
```

{% endcode %}
{% endtab %}

{% tab title="JavaScript" %}

<pre class="language-js" data-line-numbers><code class="lang-js">const { PDFNet } = require('@pdftron/pdfnet-node');
async function main() {
  await PDFNet.addResourceSearchPath('./lib/');
  // check if the module is available
  if (!(await PDFNet.StructuredOutputModule.isModuleAvailable())) {
    return;
  }
  await PDFNet.Convert.fileToPowerPoint('./input.pdf', 'output.pptx');
}
PDFNet.runWithCleanup(main, '<code class="expression">visitor.claims.serverKey || "YOUR_LICENSE_KEY"</code>');
</code></pre>

{% endtab %}

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

```php
$powerPointOutputOptions = new PowerPointOutputOptions();
// Optionally convert only the first page
$powerPointOutputOptions->SetPages(1, 1);
// Requires the Structured Output module
Convert::ToPowerPoint($filename, $output_filename, powerPointOutputOptions);
```

{% endcode %}
{% endtab %}

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

```python
powerPointOutputOptions = PowerPointOutputOptions()
# Optionally convert only the first page
powerPointOutputOptions.SetPages(1, 1)
# Requires the Structured Output module
Convert.ToPowerPoint(filename, output_filename, powerPointOutputOptions)
```

{% endcode %}
{% endtab %}

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

```ruby
$powerPointOutputOptions = Convert::PowerPointOutputOptions.new()
# Optionally convert only the first page
$powerPointOutputOptions.SetPages(1, 1);
# Requires the Structured Output module
Convert.toPowerPoint(filename, output_filename, $powerPointOutputOptions)
```

{% endcode %}
{% endtab %}

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

```vb
Dim powerPointOutputOptions As pdftron.PDF.Convert.PowerPointOutputOptions = New pdftron.PDF.Convert.PowerPointOutputOptions()
' Optionally convert only the first page
powerPointOutputOptions.SetPages(1, 1)
' Requires the Structured Output module
Convert.ToPowerPoint(filename, output_filename, powerPointOutputOptions)
```

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

## Convert PDF to Excel

This sample demonstrates how to convert from a PDF to XLSX file.

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

```csharp
Convert.ExcelOutputOptions excelOutputOptions = new Convert.ExcelOutputOptions();
// Optionally convert only the first page
excelOutputOptions.SetPages(1, 1);
// Requires the Structured Output module
Convert.ToExcel(filename, output_filename, excelOutputOptions);
```

{% endcode %}
{% endtab %}

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

```cpp
Convert::ExcelOutputOptions excelOutputOptions;
// Optionally convert only the first page
excelOutputOptions.SetPages(1, 1);
// Requires the Structured Output module
Convert::ToExcel(filename, output_filename, excelOutputOptions);
```

{% endcode %}
{% endtab %}

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

```go
excelOutputOptions := NewExcelOutputOptions()
// Optionally convert only the first page
excelOutputOptions.SetPages(1, 1)
// Requires the Structured Output module
ConvertToExcel(filename, output_filename, excelOutputOptions)
```

{% endcode %}
{% endtab %}

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

```java
Convert.ExcelOutputOptions excelOutputOptions = new Convert.ExcelOutputOptions();
// Optionally convert only the first page
excelOutputOptions.setPages(1, 1);
// Requires the Structured Output module
Convert.toExcel(filename, output_filename, excelOutputOptions);
```

{% endcode %}
{% endtab %}

{% tab title="JavaScript" %}

<pre class="language-js" data-line-numbers><code class="lang-js">const { PDFNet } = require('@pdftron/pdfnet-node');
async function main() {
  await PDFNet.addResourceSearchPath('./lib/');
  // check if the module is available
  if (!(await PDFNet.StructuredOutputModule.isModuleAvailable())) {
    return;
  }
  await PDFNet.Convert.fileToExcel('./input.pdf', 'output.xlsx');
}
PDFNet.runWithCleanup(main, '<code class="expression">visitor.claims.serverKey || "YOUR_LICENSE_KEY"</code>');
</code></pre>

{% endtab %}

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

```php
$excelOutputOptions = new ExcelOutputOptions();
// Optionally convert only the first page
$excelOutputOptions->SetPages(1, 1);
// Requires the Structured Output module
Convert::ToExcel($filename, $output_filename, excelOutputOptions);
```

{% endcode %}
{% endtab %}

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

```python
excelOutputOptions = ExcelOutputOptions()
# Optionally convert only the first page
excelOutputOptions.SetPages(1, 1)
# Requires the Structured Output module
Convert.ToExcel(filename, output_filename, excelOutputOptions)
```

{% endcode %}
{% endtab %}

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

```ruby
$excelOutputOptions = Convert::ExcelOutputOptions.new()
# Optionally convert only the first page
$excelOutputOptions.SetPages(1, 1);
# Requires the Structured Output module
Convert.toExcel(filename, output_filename, $excelOutputOptions)
```

{% endcode %}
{% endtab %}

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

```vb
Dim excelOutputOptions As pdftron.PDF.Convert.ExcelOutputOptions = New pdftron.PDF.Convert.ExcelOutputOptions()
' Optionally convert only the first page
excelOutputOptions.SetPages(1, 1)
' Requires the Structured Output module
Convert.ToExcel(filename, output_filename, excelOutputOptions)
```

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

## Full Sample Code

[Convert PDF files to MS Office](/core/get-started/samples/converttest.md) Full sample code which illustrates how to convert PDF to MS Office files (Word, Excel, PowerPoint). Code sample is available in C++, C#, Java, Python, Go, 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 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/conversion/convert-to-office.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 `automate deployments from our CI pipeline` 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.
