> 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, C++, Java, PHP, Ruby, and Go

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