> 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/get-started/samples/pdf2officetest.md).

# Convert PDF to DOCX, XSLX - PDF2Office

Sample code for using Apryse SDK to convert generic PDF documents to Office format, provided in Python, C++, C#, Java, Node.js (JavaScript), PHP, Ruby, Go and VB.

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

*These packages are required to use these features in production. Trial keys have unlimited access to all features*

<a href="/core/get-started/get-started.md" class="button primary">Server SDK</a><a href="https://apryse.com/capabilities#OfficeConversion" class="button primary">Package: Office Conversion</a><a href="/core/learn-more/modules.md#structured-output-module" class="button primary">Module: Structured Output</a>
{% endhint %}

Sample code for using Apryse SDK to programmatically convert generic PDF documents to Word, Excel, PowerPoint; provided in Python, C++, C#, Go, Java, Node.js (JavaScript), PHP, Ruby and VB.

To convert files to Office with this Apryse Server SDK sample code:

1. Complete the [Get started with Server SDK](/core/get-started/get-started.md) process in your language/framework.
2. After you complete the Get Started with Server SDK work in your language/framework from Step 1 above, next, download [the Structured Output Module](/core/learn-more/modules.md#structured-output-module).
3. Add sample code provided in this guide

To use this feature in production, your license key will need the [Office Conversion Package](https://apryse.com/capabilities#OfficeConversion). Trial keys already include all packages.

Learn more about our [Server SDK](/core/get-started/get-started.md) and [PDF to Office Conversion](/core/conversion/convert-to-office.md).

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

```csharp
//
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
//

using System;
using pdftron;
using pdftron.Common;
using pdftron.PDF;

namespace PDF2OfficeTestCS
{
	/// <summary>
	// The following sample illustrates how to use the PDF::Convert utility class to convert 
	// documents and files to Office.
	//
	// The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
	// and other documents into Word, Excel, PowerPoint and HTML format.
	//
	// The Apryse SDK Structured Output add-on module can be downloaded from
	// https://docs.apryse.com/core/info/modules/
	//
	// Please contact us if you have any questions.	
	/// </summary>

	class Class1
	{
		private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();

		static Class1() {}

		// Relative path to the folder containing test files.
		const string inputPath = "../../../../TestFiles/";
		const string outputPath = "../../../../TestFiles/Output/";

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static int Main(string[] args)
		{
			// The first step in every application using PDFNet is to initialize the 
			// library. The library is usually initialized only once, but calling 
			// Initialize() multiple times is also fine.
			PDFNet.Initialize(PDFTronLicense.Key);

			PDFNet.AddResourceSearchPath("../../../../../Lib/");

			if (!StructuredOutputModule.IsModuleAvailable())
			{
				Console.WriteLine();
				Console.WriteLine("Unable to run the sample: Apryse SDK Structured Output module not available.");
				Console.WriteLine("-----------------------------------------------------------------------------");
				Console.WriteLine("The Structured Output module is an optional add-on, available for download");
				Console.WriteLine("at https://docs.apryse.com/core/info/modules/. If you have already");
				Console.WriteLine("downloaded this module, ensure that the SDK is able to find the required files");
				Console.WriteLine("using the PDFNet::AddResourceSearchPath() function.");
				Console.WriteLine();
				return 0;
			}

			bool err = false;

			//////////////////////////////////////////////////////////////////////////
			// Word
			//////////////////////////////////////////////////////////////////////////

			try
			{
				// Convert PDF document to Word
				Console.WriteLine("Converting PDF to Word");

				string outputFile = outputPath + "paragraphs_and_tables.docx";

				pdftron.PDF.Convert.ToWord(inputPath + "paragraphs_and_tables.pdf", outputFile);

				Console.WriteLine("Result saved in " + outputFile);
			}
			catch (PDFNetException e)
			{
				Console.WriteLine("Unable to convert PDF document to Word, error: " + e.Message);
				err = true;
			}
			catch (Exception e)
			{
				Console.WriteLine("Unknown Exception, error: ");
				Console.WriteLine(e);
				err = true;
			}

			//////////////////////////////////////////////////////////////////////////

			try
			{
				// Convert PDF document to Word with options
				Console.WriteLine("Converting PDF to Word with options");

				string outputFile = outputPath + "paragraphs_and_tables_first_page.docx";

				pdftron.PDF.Convert.WordOutputOptions wordOutputOptions = new pdftron.PDF.Convert.WordOutputOptions();

				// Convert only the first page
				wordOutputOptions.SetPages(1, 1);

				pdftron.PDF.Convert.ToWord(inputPath + "paragraphs_and_tables.pdf", outputFile, wordOutputOptions);

				Console.WriteLine("Result saved in " + outputFile);
			}
			catch (PDFNetException e)
			{
				Console.WriteLine("Unable to convert PDF document to Word, error: " + e.Message);
				err = true;
			}
			catch (Exception e)
			{
				Console.WriteLine("Unknown Exception, error: ");
				Console.WriteLine(e);
				err = true;
			}

			//////////////////////////////////////////////////////////////////////////
			// Excel
			//////////////////////////////////////////////////////////////////////////

			try
			{
				// Convert PDF document to Excel
				Console.WriteLine("Converting PDF to Excel");

				string outputFile = outputPath + "paragraphs_and_tables.xlsx";

				pdftron.PDF.Convert.ToExcel(inputPath + "paragraphs_and_tables.pdf", outputFile);

				Console.WriteLine("Result saved in " + outputFile);
			}
			catch (PDFNetException e)
			{
				Console.WriteLine("Unable to convert PDF document to Excel, error: " + e.Message);
				err = true;
			}
			catch (Exception e)
			{
				Console.WriteLine("Unknown Exception, error: ");
				Console.WriteLine(e);
				err = true;
			}

			//////////////////////////////////////////////////////////////////////////

			try
			{
				// Convert PDF document to Excel with options
				Console.WriteLine("Converting PDF to Excel with options");

				string outputFile = outputPath + "paragraphs_and_tables_second_page.xlsx";

				pdftron.PDF.Convert.ExcelOutputOptions excelOutputOptions = new pdftron.PDF.Convert.ExcelOutputOptions();

				// Convert only the second page
				excelOutputOptions.SetPages(2, 2);

				pdftron.PDF.Convert.ToExcel(inputPath + "paragraphs_and_tables.pdf", outputFile, excelOutputOptions);

				Console.WriteLine("Result saved in " + outputFile);
			}
			catch (PDFNetException e)
			{
				Console.WriteLine("Unable to convert PDF document to Excel, error: " + e.Message);
				err = true;
			}
			catch (Exception e)
			{
				Console.WriteLine("Unknown Exception, error: ");
				Console.WriteLine(e);
				err = true;
			}

			//////////////////////////////////////////////////////////////////////////
			// PowerPoint
			//////////////////////////////////////////////////////////////////////////

			try
			{
				// Convert PDF document to PowerPoint
				Console.WriteLine("Converting PDF to PowerPoint");

				string outputFile = outputPath + "paragraphs_and_tables.pptx";

				pdftron.PDF.Convert.ToPowerPoint(inputPath + "paragraphs_and_tables.pdf", outputFile);

				Console.WriteLine("Result saved in " + outputFile);
			}
			catch (PDFNetException e)
			{
				Console.WriteLine("Unable to convert PDF document to PowerPoint, error: " + e.Message);
				err = true;
			}
			catch (Exception e)
			{
				Console.WriteLine("Unknown Exception, error: ");
				Console.WriteLine(e);
				err = true;
			}

			//////////////////////////////////////////////////////////////////////////

			try
			{
				// Convert PDF document to PowerPoint with options
				Console.WriteLine("Converting PDF to PowerPoint with options");

				string outputFile = outputPath + "paragraphs_and_tables_first_page.pptx";

				pdftron.PDF.Convert.PowerPointOutputOptions powerPointOutputOptions = new pdftron.PDF.Convert.PowerPointOutputOptions();

				// Convert only the first page
				powerPointOutputOptions.SetPages(1, 1);

				pdftron.PDF.Convert.ToPowerPoint(inputPath + "paragraphs_and_tables.pdf", outputFile, powerPointOutputOptions);

				Console.WriteLine("Result saved in " + outputFile);
			}
			catch (PDFNetException e)
			{
				Console.WriteLine("Unable to convert PDF document to PowerPoint, error: " + e.Message);
				err = true;
			}
			catch (Exception e)
			{
				Console.WriteLine("Unknown Exception, error: ");
				Console.WriteLine(e);
				err = true;
			}

			//////////////////////////////////////////////////////////////////////////

			PDFNet.Terminate();
			Console.WriteLine("Done.");
			return (err == false ? 0 : 1);
		}
	}
}
```

{% endcode %}
{% endtab %}

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

```cpp
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

#include <iostream>
#include <sstream>
#include <PDF/PDFNet.h>
#include <PDF/Convert.h>
#include <PDF/StructuredOutputModule.h>
#include "../../LicenseKey/CPP/LicenseKey.h"

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF::Convert utility class to convert 
// documents and files to Office.
//
// The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
// and other documents into Word, Excel, PowerPoint and HTML format.
//
// The Apryse SDK Structured Output module can be downloaded from
// https://docs.apryse.com/core/info/modules/
//
// Please contact us if you have any questions.	
//---------------------------------------------------------------------------------------

using namespace pdftron;
using namespace PDF;
using namespace std;

UString inputPath("../../TestFiles/");
UString outputPath("../../TestFiles/Output/");

int main(int argc, char *argv[])
{	
	// The first step in every application using PDFNet is to initialize the 
	// library. The library is usually initialized only once, but calling 
	// Initialize() multiple times is also fine.
	PDFNet::Initialize(LicenseKey);

	PDFNet::AddResourceSearchPath("../../../Lib/");

	if (!StructuredOutputModule::IsModuleAvailable())
	{
		cout << endl;
		cout << "Unable to run the sample: Apryse SDK Structured Output module not available." << endl;
		cout << "-----------------------------------------------------------------------------" << endl;
		cout << "The Structured Output module is an optional add-on, available for download" << endl;
		cout << "at https://docs.apryse.com/core/info/modules/. If you have already" << endl;
		cout << "downloaded this module, ensure that the SDK is able to find the required files" << endl;
		cout << "using the PDFNet::AddResourceSearchPath() function." << endl;
		cout << endl;
		return 1;
	}

	int err = 0;

	//////////////////////////////////////////////////////////////////////////
	// Word
	//////////////////////////////////////////////////////////////////////////

	try
	{
		// Convert PDF document to Word
		cout << "Converting PDF to Word" << endl;

		UString outputFile = outputPath + "paragraphs_and_tables.docx";

		Convert::ToWord(inputPath + "paragraphs_and_tables.pdf", outputFile);

		cout << "Result saved in " << outputFile.ConvertToUtf8().c_str() << endl;
	}
	catch (Common::Exception& e)
	{
		cout << "Unable to convert PDF document to Word, error: " << e << endl;
		err = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		err = 1;
	}

	//////////////////////////////////////////////////////////////////////////

	try
	{
		// Convert PDF document to Word with options
		cout << "Converting PDF to Word with options" << endl;

		UString outputFile = outputPath + "paragraphs_and_tables_first_page.docx";

		Convert::WordOutputOptions wordOutputOptions;

		// Convert only the first page
		wordOutputOptions.SetPages(1, 1);

		Convert::ToWord(inputPath + "paragraphs_and_tables.pdf", outputFile, wordOutputOptions);

		cout << "Result saved in " << outputFile.ConvertToUtf8().c_str() << endl;
	}
	catch (Common::Exception& e)
	{
		cout << "Unable to convert PDF document to Word, error: " << e << endl;
		err = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		err = 1;
	}

	//////////////////////////////////////////////////////////////////////////
	// Excel
	//////////////////////////////////////////////////////////////////////////

	try
	{
		// Convert PDF document to Excel
		cout << "Converting PDF to Excel" << endl;

		UString outputFile = outputPath + "paragraphs_and_tables.xlsx";

		Convert::ToExcel(inputPath + "paragraphs_and_tables.pdf", outputFile);

		cout << "Result saved in " << outputFile.ConvertToUtf8().c_str() << endl;
	}
	catch (Common::Exception& e)
	{
		cout << "Unable to convert PDF document to Excel, error: " << e << endl;
		err = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		err = 1;
	}

	//////////////////////////////////////////////////////////////////////////

	try
	{
		// Convert PDF document to Excel with options
		cout << "Converting PDF to Excel with options" << endl;

		UString outputFile = outputPath + "paragraphs_and_tables_second_page.xlsx";

		Convert::ExcelOutputOptions excelOutputOptions;

		// Convert only the second page
		excelOutputOptions.SetPages(2, 2);

		Convert::ToExcel(inputPath + "paragraphs_and_tables.pdf", outputFile, excelOutputOptions);

		cout << "Result saved in " << outputFile.ConvertToUtf8().c_str() << endl;
	}
	catch (Common::Exception& e)
	{
		cout << "Unable to convert PDF document to Excel, error: " << e << endl;
		err = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		err = 1;
	}

	//////////////////////////////////////////////////////////////////////////
	// PowerPoint
	//////////////////////////////////////////////////////////////////////////

	try
	{
		// Convert PDF document to PowerPoint
		cout << "Converting PDF to PowerPoint" << endl;

		UString outputFile = outputPath + "paragraphs_and_tables.pptx";

		Convert::ToPowerPoint(inputPath + "paragraphs_and_tables.pdf", outputFile);

		cout << "Result saved in " << outputFile.ConvertToUtf8().c_str() << endl;
	}
	catch (Common::Exception& e)
	{
		cout << "Unable to convert PDF document to PowerPoint, error: " << e << endl;
		err = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		err = 1;
	}

	//////////////////////////////////////////////////////////////////////////

	try
	{
		// Convert PDF document to PowerPoint with options
		cout << "Converting PDF to PowerPoint with options" << endl;

		UString outputFile = outputPath + "paragraphs_and_tables_first_page.pptx";

		Convert::PowerPointOutputOptions powerPointOutputOptions;

		// Convert only the first page
		powerPointOutputOptions.SetPages(1, 1);

		Convert::ToPowerPoint(inputPath + "paragraphs_and_tables.pdf", outputFile, powerPointOutputOptions);

		cout << "Result saved in " << outputFile.ConvertToUtf8().c_str() << endl;
	}
	catch (Common::Exception& e)
	{
		cout << "Unable to convert PDF document to PowerPoint, error: " << e << endl;
		err = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		err = 1;
	}

	//////////////////////////////////////////////////////////////////////////

	PDFNet::Terminate();
	cout << "Done.\n";
	return err;
}
```

{% endcode %}
{% endtab %}

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

```go
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------

package main
import (
	"fmt"
	. "pdftron"
)

import  "pdftron/Samples/LicenseKey/GO"

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF::Convert utility class to convert 
// documents and files to Word, Excel and PowerPoint.
//
// The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
// and other documents into Word, Excel, PowerPoint and HTML format.
//
// The PDFTron SDK Structured Output module can be downloaded from
// https://docs.apryse.com/core/info/modules/
//
// Please contact us if you have any questions.
//---------------------------------------------------------------------------------------

// Relative path to the folder containing the test files.
var inputPath = "../../TestFiles/"
var outputPath = "../../TestFiles/Output/"

//---------------------------------------------------------------------------------------

func catch(err *error) {
    if r := recover(); r != nil {
        *err = fmt.Errorf("%v", r)
    }
}

//---------------------------------------------------------------------------------------

func ConvertToWordTest() (err error) {
	defer catch(&err)

	// Convert PDF document to Word
	fmt.Println("Converting PDF to Word")

	inputFile := inputPath + "paragraphs_and_tables.pdf"
	outputFile := outputPath + "paragraphs_and_tables.docx"

	// Convert to Word
	ConvertToWord(inputFile, outputFile)

	fmt.Println("Result saved in " + outputFile)
	return nil
}

//---------------------------------------------------------------------------------------

func ConvertToWordWithOptionsTest() (err error) {
	defer catch(&err)

	// Convert PDF document to Word with options
	fmt.Println("Converting PDF to Word with options")

	inputFile := inputPath + "paragraphs_and_tables.pdf"
	outputFile := outputPath + "paragraphs_and_tables_first_page.docx"

	wordOutputOptions := NewWordOutputOptions()

	// Convert only the first page
	wordOutputOptions.SetPages(1, 1)

	// Convert to Word
	ConvertToWord(inputFile, outputFile, wordOutputOptions)

	fmt.Println("Result saved in " + outputFile)
	return nil
}

//---------------------------------------------------------------------------------------

func ConvertToExcelTest() (err error) {
	defer catch(&err)

	// Convert PDF document to Excel
	fmt.Println("Converting PDF to Excel")

	inputFile := inputPath + "paragraphs_and_tables.pdf"
	outputFile := outputPath + "paragraphs_and_tables.xlsx"

	// Convert to Excel
	ConvertToExcel(inputFile, outputFile)

	fmt.Println("Result saved in " + outputFile)
	return nil
}

//---------------------------------------------------------------------------------------

func ConvertToExcelWithOptionsTest() (err error) {
	defer catch(&err)

	// Convert PDF document to Excel with options
	fmt.Println("Converting PDF to Excel with options")

	inputFile := inputPath + "paragraphs_and_tables.pdf"
	outputFile := outputPath + "paragraphs_and_tables_second_page.xlsx"

	excelOutputOptions := NewExcelOutputOptions()

	// Convert only the second page
	excelOutputOptions.SetPages(2, 2)

	// Convert to Excel
	ConvertToExcel(inputFile, outputFile, excelOutputOptions)

	fmt.Println("Result saved in " + outputFile)
	return nil
}

//---------------------------------------------------------------------------------------

func ConvertToPowerPointTest() (err error) {
	defer catch(&err)

	// Convert PDF document to PowerPoint
	fmt.Println("Converting PDF to PowerPoint")

	inputFile := inputPath + "paragraphs_and_tables.pdf"
	outputFile := outputPath + "paragraphs_and_tables.pptx"

	// Convert to PowerPoint
	ConvertToPowerPoint(inputFile, outputFile)

	fmt.Println("Result saved in " + outputFile)
	return nil
}

//---------------------------------------------------------------------------------------

func ConvertToPowerPointWithOptionsTest() (err error) {
	defer catch(&err)

	// Convert PDF document to PowerPoint with options
	fmt.Println("Converting PDF to PowerPoint with options")

	inputFile := inputPath + "paragraphs_and_tables.pdf"
	outputFile := outputPath + "paragraphs_and_tables_first_page.pptx"

	powerPointOutputOptions := NewPowerPointOutputOptions()

	// Convert only the first page
	powerPointOutputOptions.SetPages(1, 1)

	// Convert to PowerPoint
	ConvertToPowerPoint(inputFile, outputFile, powerPointOutputOptions)

	fmt.Println("Result saved in " + outputFile)
	return nil
}

//---------------------------------------------------------------------------------------

func main() {
    // The first step in every application using PDFNet is to initialize the 
    // library. The library is usually initialized only once, but calling 
    // Initialize() multiple times is also fine.
    PDFNetInitialize(PDFTronLicense.Key)

	//-----------------------------------------------------------------------------------

	PDFNetAddResourceSearchPath("../../../PDFNetC/Lib/")

	if !StructuredOutputModuleIsModuleAvailable() {
		fmt.Println("")
		fmt.Println("Unable to run the sample: PDFTron SDK Structured Output module not available.")
		fmt.Println("-----------------------------------------------------------------------------")
		fmt.Println("The Structured Output module is an optional add-on, available for download")
		fmt.Println("at https://docs.apryse.com/core/info/modules/. If you have already")
		fmt.Println("downloaded this module, ensure that the SDK is able to find the required files")
		fmt.Println("using the PDFNet::AddResourceSearchPath() function.")
		fmt.Println("")
		return
	}

	//-----------------------------------------------------------------------------------

	// Convert PDF document to Word
	err := ConvertToWordTest()
	if err != nil {
		fmt.Println(fmt.Errorf("Unable to convert PDF document to Word, error: %s", err))
	}

	//-----------------------------------------------------------------------------------

	// Convert PDF document to Word with options
	err = ConvertToWordWithOptionsTest()
	if err != nil {
		fmt.Println(fmt.Errorf("Unable to convert PDF document to Word, error: %s", err))
	}

	//-----------------------------------------------------------------------------------

	// Convert PDF document to Excel
	err = ConvertToExcelTest()
	if err != nil {
		fmt.Println(fmt.Errorf("Unable to convert PDF document to Excel, error: %s", err))
	}

	//-----------------------------------------------------------------------------------

	// Convert PDF document to Excel with options
	err = ConvertToExcelWithOptionsTest()
	if err != nil {
		fmt.Println(fmt.Errorf("Unable to convert PDF document to Excel, error: %s", err))
	}

	//-----------------------------------------------------------------------------------

	// Convert PDF document to PowerPoint
	err = ConvertToPowerPointTest()
	if err != nil {
		fmt.Println(fmt.Errorf("Unable to convert PDF document to PowerPoint, error: %s", err))
	}

	//-----------------------------------------------------------------------------------

	// Convert PDF document to PowerPoint with options
	err = ConvertToPowerPointWithOptionsTest()
	if err != nil {
		fmt.Println(fmt.Errorf("Unable to convert PDF document to PowerPoint, error: %s", err))
	}

	//-----------------------------------------------------------------------------------

    PDFNetTerminate()
    fmt.Println("Done.")
}
```

{% endcode %}
{% endtab %}

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

```java
//
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

import com.pdftron.common.PDFNetException;
import com.pdftron.pdf.*;

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF::Convert utility class to convert 
// documents and files to Office.
//
// The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
// and other documents into Word, Excel, PowerPoint and HTML format.
//
// The Apryse SDK Structured Output module can be downloaded from
// https://docs.apryse.com/core/info/modules/
//
// Please contact us if you have any questions.
//---------------------------------------------------------------------------------------

public class PDF2OfficeTest 
{
    // Relative path to the folder containing test files.
    static String inputPath = "../../TestFiles/";
    static String outputPath = "../../TestFiles/Output/";

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    public static void main(String[] args) 
    {
        // The first step in every application using PDFNet is to initialize the 
        // library. The library is usually initialized only once, but calling 
        // Initialize() multiple times is also fine.
        PDFNet.initialize(PDFTronLicense.Key());

        PDFNet.addResourceSearchPath("../../../Lib/");

        try {
            if (!StructuredOutputModule.isModuleAvailable()) {
                System.out.println();
                System.out.println("Unable to run the sample: Apryse SDK Structured Output module not available.");
                System.out.println("-----------------------------------------------------------------------------");
                System.out.println("The Structured Output module is an optional add-on, available for download");
                System.out.println("at https://docs.apryse.com/core/info/modules/. If you have already");
                System.out.println("downloaded this module, ensure that the SDK is able to find the required files");
                System.out.println("using the PDFNet::AddResourceSearchPath() function.");
                System.out.println();
                return;
            }
        } catch (PDFNetException e) {
            System.out.println(e);
            return;
        }  catch (Exception e) {
            System.out.println(e);
            return;
        }

        boolean err = false;

        //////////////////////////////////////////////////////////////////////////
        // Word
        //////////////////////////////////////////////////////////////////////////

        try {
            // Convert PDF document to Word
            System.out.println("Converting PDF to Word");

            String outputFile = outputPath + "paragraphs_and_tables.docx";

            Convert.toWord(inputPath + "paragraphs_and_tables.pdf", outputFile);

            System.out.println("Result saved in " + outputFile);
        } catch (PDFNetException e) {
            System.out.println("Unable to convert PDF document to Word, error: ");
            System.out.println(e);
            err = true;
        }  catch (Exception e) {
            System.out.println("Unknown Exception, error: ");
            System.out.println(e);
            err = true;
        }

        //////////////////////////////////////////////////////////////////////////

        try {
            // Convert PDF document to Word with options
            System.out.println("Converting PDF to Word with options");

            String outputFile = outputPath + "paragraphs_and_tables_first_page.docx";

            Convert.WordOutputOptions wordOutputOptions = new Convert.WordOutputOptions();

            // Convert only the first page
            wordOutputOptions.setPages(1, 1);

            Convert.toWord(inputPath + "paragraphs_and_tables.pdf", outputFile, wordOutputOptions);

            System.out.println("Result saved in " + outputFile);
        } catch (PDFNetException e) {
            System.out.println("Unable to convert PDF document to Word, error: ");
            System.out.println(e);
            err = true;
        }  catch (Exception e) {
            System.out.println("Unknown Exception, error: ");
            System.out.println(e);
            err = true;
        }

        //////////////////////////////////////////////////////////////////////////
        // Excel
        //////////////////////////////////////////////////////////////////////////

        try {
            // Convert PDF document to Excel
            System.out.println("Converting PDF to Excel");

            String outputFile = outputPath + "paragraphs_and_tables.xlsx";

            Convert.toExcel(inputPath + "paragraphs_and_tables.pdf", outputFile);

            System.out.println("Result saved in " + outputFile);
        } catch (PDFNetException e) {
            System.out.println("Unable to convert PDF document to Excel, error: ");
            System.out.println(e);
            err = true;
        }  catch (Exception e) {
            System.out.println("Unknown Exception, error: ");
            System.out.println(e);
            err = true;
        }

        //////////////////////////////////////////////////////////////////////////

        try (PDFDoc doc = new PDFDoc()) {
            // Convert PDF document to Excel with options
            System.out.println("Converting PDF to Excel with options");

            String outputFile = outputPath + "paragraphs_and_tables_second_page.xlsx";

            Convert.ExcelOutputOptions excelOutputOptions = new Convert.ExcelOutputOptions();

            // Convert only the second page
            excelOutputOptions.setPages(2, 2);

            Convert.toExcel(inputPath + "paragraphs_and_tables.pdf", outputFile, excelOutputOptions);

            System.out.println("Result saved in " + outputFile);
        } catch (PDFNetException e) {
            System.out.println("Unable to convert PDF document to Excel, error: ");
            System.out.println(e);
            err = true;
        }  catch (Exception e) {
            System.out.println("Unknown Exception, error: ");
            System.out.println(e);
            err = true;
        }

        //////////////////////////////////////////////////////////////////////////
        // PowerPoint
        //////////////////////////////////////////////////////////////////////////

        try {
            // Convert PDF document to PowerPoint
            System.out.println("Converting PDF to PowerPoint");

            String outputFile = outputPath + "paragraphs_and_tables.pptx";

            Convert.toPowerPoint(inputPath + "paragraphs_and_tables.pdf", outputFile);

            System.out.println("Result saved in " + outputFile);
        } catch (PDFNetException e) {
            System.out.println("Unable to convert PDF document to PowerPoint, error: ");
            System.out.println(e);
            err = true;
        }  catch (Exception e) {
            System.out.println("Unknown Exception, error: ");
            System.out.println(e);
            err = true;
        }

        //////////////////////////////////////////////////////////////////////////

        try {
            // Convert PDF document to PowerPoint with options
            System.out.println("Converting PDF to PowerPoint with options");

            String outputFile = outputPath + "paragraphs_and_tables_first_page.pptx";

            Convert.PowerPointOutputOptions powerPointOutputOptions = new Convert.PowerPointOutputOptions();

            // Convert only the first page
            powerPointOutputOptions.setPages(1, 1);

            Convert.toPowerPoint(inputPath + "paragraphs_and_tables.pdf", outputFile, powerPointOutputOptions);

            System.out.println("Result saved in " + outputFile);
        } catch (PDFNetException e) {
            System.out.println("Unable to convert PDF document to PowerPoint, error: ");
            System.out.println(e);
            err = true;
        }  catch (Exception e) {
            System.out.println("Unknown Exception, error: ");
            System.out.println(e);
            err = true;
        }

        //////////////////////////////////////////////////////////////////////////

        PDFNet.terminate();
        System.out.println("Done.");        
    }
}
```

{% endcode %}
{% endtab %}

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

```js
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF::Convert utility class to convert 
// documents and files to Word, Excel and PowerPoint.
//
// The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
// and other documents into Word, Excel, PowerPoint and HTML format.
//
// The Apryse SDK Structured Output module can be downloaded from
// https://docs.apryse.com/core/info/modules/
//
// Please contact us if you have any questions.	
//---------------------------------------------------------------------------------------

const { PDFNet } = require('@pdftron/pdfnet-node');
const PDFTronLicense = require('../LicenseKey/LicenseKey');

((exports) => {
	'use strict';

	exports.runPDF2OfficeTest = () => {

		const main = async () => {

			const inputPath = '../TestFiles/';
			const outputPath = '../TestFiles/Output/';

			//////////////////////////////////////////////////////////////////////////

			await PDFNet.addResourceSearchPath('../../lib/');

			if (!await PDFNet.StructuredOutputModule.isModuleAvailable()) {
				console.log('\nUnable to run the sample: Apryse SDK Structured Output module not available.');
				console.log('---------------------------------------------------------------');
				console.log('The Structured Output module is an optional add-on, available for download');
				console.log('at https://docs.apryse.com/core/info/modules/. If you have already');
				console.log('downloaded this module, ensure that the SDK is able to find the required files');
				console.log('using the PDFNet::AddResourceSearchPath() function.\n');

				return;
			}

			//////////////////////////////////////////////////////////////////////////

			try {
				// Convert PDF document to Word
				console.log('Converting PDF to Word');

				const outputFile = outputPath + 'paragraphs_and_tables.docx';

				await PDFNet.Convert.fileToWord(inputPath + 'paragraphs_and_tables.pdf', outputFile);

				console.log('Result saved in ' + outputFile);
			} catch (err) {
				console.log(err);
			}

			try {
				// Convert PDF document to Word with options
				console.log('Converting PDF to Word with options');

				const outputFile = outputPath + 'paragraphs_and_tables_first_page.docx';

				const wordOutputOptions = new PDFNet.Convert.WordOutputOptions();

				// Convert only the first page
				wordOutputOptions.setPages(1, 1);

				await PDFNet.Convert.fileToWord(inputPath + 'paragraphs_and_tables.pdf', outputFile, wordOutputOptions);

				console.log('Result saved in ' + outputFile);
			} catch (err) {
				console.log(err);
			}

			//////////////////////////////////////////////////////////////////////////

			try {
				// Convert PDF document to Excel
				console.log('Converting PDF to Excel');

				const outputFile = outputPath + 'paragraphs_and_tables.xlsx';

				await PDFNet.Convert.fileToExcel(inputPath + 'paragraphs_and_tables.pdf', outputFile);

				console.log('Result saved in ' + outputFile);
			} catch (err) {
				console.log(err);
			}

			try {
				// Convert PDF document to Excel with options
				console.log('Converting PDF to Excel with options');

				const outputFile = outputPath + 'paragraphs_and_tables_second_page.xlsx';

				const excelOutputOptions = new PDFNet.Convert.ExcelOutputOptions();

				// Convert only the second page
				excelOutputOptions.setPages(2, 2);

				await PDFNet.Convert.fileToExcel(inputPath + 'paragraphs_and_tables.pdf', outputFile, excelOutputOptions);

				console.log('Result saved in ' + outputFile);
			} catch (err) {
				console.log(err);
			}

			//////////////////////////////////////////////////////////////////////////

			try {
				// Convert PDF document to PowerPoint
				console.log('Converting PDF to PowerPoint');

				const outputFile = outputPath + 'paragraphs_and_tables.pptx';

				await PDFNet.Convert.fileToPowerPoint(inputPath + 'paragraphs_and_tables.pdf', outputFile);

				console.log('Result saved in ' + outputFile);
			} catch (err) {
				console.log(err);
			}

			try {
				// Convert PDF document to PowerPoint with options
				console.log('Converting PDF to PowerPoint with options');

				const outputFile = outputPath + 'paragraphs_and_tables_first_page.pptx';

				const powerPointOutputOptions = new PDFNet.Convert.PowerPointOutputOptions();

				// Convert only the first page
				powerPointOutputOptions.setPages(1, 1);

				await PDFNet.Convert.fileToPowerPoint(inputPath + 'paragraphs_and_tables.pdf', outputFile, powerPointOutputOptions);

				console.log('Result saved in ' + outputFile);
			} catch (err) {
				console.log(err);
			}

			//////////////////////////////////////////////////////////////////////////

			console.log('Done.');
		};

		PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
			console.log('Error: ' + JSON.stringify(error));
		}).then(function () { return PDFNet.shutdown(); });
	};
	exports.runPDF2OfficeTest();
})(exports);
// eslint-disable-next-line spaced-comment
//# sourceURL=PDF2OfficeTest.js
```

{% endcode %}
{% endtab %}

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

```php
<?php
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------
if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
include("../../../PDFNetC/Lib/PDFNetPHP.php");
include("../../LicenseKey/PHP/LicenseKey.php");

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF::Convert utility class to convert 
// documents and files to Word, Excel and PowerPoint.
//
// The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
// and other documents into Word, Excel, PowerPoint and HTML format.
//
// The PDFTron SDK Structured Output module can be downloaded from
// https://docs.apryse.com/core/info/modules/
//
// Please contact us if you have any questions.
//---------------------------------------------------------------------------------------

function main()
{
	// Relative path to the folder containing the test files.
	$inputPath = getcwd()."/../../TestFiles/";
	$outputPath = $inputPath."Output/";

	// The first step in every application using PDFNet is to initialize the 
	// library. The library is usually initialized only once, but calling 
	// Initialize() multiple times is also fine.
	global $LicenseKey;
	PDFNet::Initialize($LicenseKey);
	PDFNet::GetSystemFontList();    // Wait for fonts to be loaded if they haven't already. This is done because PHP can run into errors when shutting down if font loading is still in progress.
	
	//-----------------------------------------------------------------------------------

	PDFNet::AddResourceSearchPath("../../../PDFNetC/Lib/");

	if (!StructuredOutputModule::IsModuleAvailable()) {
		echo(nl2br("\n"));
		echo(nl2br("Unable to run the sample: PDFTron SDK Structured Output module not available.\n"));
		echo(nl2br("-----------------------------------------------------------------------------\n"));
		echo(nl2br("The Structured Output module is an optional add-on, available for download\n"));
		echo(nl2br("at https://docs.apryse.com/core/info/modules/. If you have already\n"));
		echo(nl2br("downloaded this module, ensure that the SDK is able to find the required files\n"));
		echo(nl2br("using the PDFNet::AddResourceSearchPath() function.\n"));
		echo(nl2br("\n"));
		return;
	}

	//-----------------------------------------------------------------------------------

	try {
		// Convert PDF document to Word
		echo(nl2br("Converting PDF to Word\n"));

		$outputFile = $outputPath."paragraphs_and_tables.docx";

		Convert::ToWord($inputPath."paragraphs_and_tables.pdf", $outputFile);

		echo(nl2br("Result saved in " . $outputFile . "\n"));
	}
	catch(Exception $e) {
		echo(nl2br("Unable to convert PDF document to Word, error: " . $e->getMessage() . "\n"));
	}

	//-----------------------------------------------------------------------------------

	try {
		// Convert PDF document to Word with options
		echo(nl2br("Converting PDF to Word with options\n"));

		$outputFile = $outputPath."paragraphs_and_tables_first_page.docx";

		$wordOutputOptions = new WordOutputOptions(); // Convert::WordOutputOptions();

		// Convert only the first page
		$wordOutputOptions->SetPages(1, 1);

		Convert::ToWord($inputPath."paragraphs_and_tables.pdf", $outputFile, $wordOutputOptions);

		echo(nl2br("Result saved in " . $outputFile . "\n"));
	}
	catch(Exception $e) {
		echo(nl2br("Unable to convert PDF document to Word, error: " . $e->getMessage() . "\n"));
	}

	//-----------------------------------------------------------------------------------

	try {
		// Convert PDF document to Excel
		echo(nl2br("Converting PDF to Excel\n"));

		$outputFile = $outputPath."paragraphs_and_tables.xlsx";

		Convert::ToExcel($inputPath."paragraphs_and_tables.pdf", $outputFile);

		echo(nl2br("Result saved in " . $outputFile . "\n"));
	}
	catch(Exception $e) {
		echo(nl2br("Unable to convert PDF document to Excel, error: " . $e->getMessage() . "\n"));
	}

	//-----------------------------------------------------------------------------------

	try {
		// Convert PDF document to Excel with options
		echo(nl2br("Converting PDF to Excel with options\n"));

		$outputFile = $outputPath."paragraphs_and_tables_second_page.xlsx";

		$excelOutputOptions = new ExcelOutputOptions(); // Convert::ExcelOutputOptions();

		// Convert only the second page
		$excelOutputOptions->SetPages(2, 2);

		Convert::ToExcel($inputPath."paragraphs_and_tables.pdf", $outputFile, $excelOutputOptions);

		echo(nl2br("Result saved in " . $outputFile . "\n"));
	}
	catch(Exception $e) {
		echo(nl2br("Unable to convert PDF document to Excel, error: " . $e->getMessage() . "\n"));
	}

	//-----------------------------------------------------------------------------------

	try {
		// Convert PDF document to PowerPoint
		echo(nl2br("Converting PDF to PowerPoint\n"));

		$outputFile = $outputPath."paragraphs_and_tables.pptx";

		Convert::ToPowerPoint($inputPath."paragraphs_and_tables.pdf", $outputFile);

		echo(nl2br("Result saved in " . $outputFile . "\n"));
	}
	catch(Exception $e) {
		echo(nl2br("Unable to convert PDF document to PowerPoint, error: " . $e->getMessage() . "\n"));
	}

	//-----------------------------------------------------------------------------------

	try {
		// Convert PDF document to PowerPoint with options
		echo(nl2br("Converting PDF to PowerPoint with options\n"));

		$outputFile = $outputPath."paragraphs_and_tables_first_page.pptx";

		$powerPointOutputOptions = new PowerPointOutputOptions(); // Convert::PowerPointOutputOptions();

		// Convert only the first page
		$powerPointOutputOptions->SetPages(1, 1);

		Convert::ToPowerPoint($inputPath."paragraphs_and_tables.pdf", $outputFile, $powerPointOutputOptions);

		echo(nl2br("Result saved in " . $outputFile . "\n"));
	}
	catch(Exception $e) {
		echo(nl2br("Unable to convert PDF document to PowerPoint, error: " . $e->getMessage() . "\n"));
	}

	//-----------------------------------------------------------------------------------

	PDFNet::Terminate();
	echo(nl2br("Done.\n"));
}

main();
?>
```

{% endcode %}
{% endtab %}

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

```python
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

import site
site.addsitedir("../../../PDFNetC/Lib")
import sys
from PDFNetPython import *

import platform

sys.path.append("../../LicenseKey/PYTHON")
from LicenseKey import *

#---------------------------------------------------------------------------------------
# The following sample illustrates how to use the PDF.Convert utility class to convert 
# documents and files to Word, Excel and PowerPoint.
#
# The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
# and other documents into Word, Excel, PowerPoint and HTML format.
#
# The PDFTron SDK Structured Output module can be downloaded from
# https://docs.apryse.com/core/info/modules/
#
# Please contact us if you have any questions.
#---------------------------------------------------------------------------------------

# Relative path to the folder containing the test files.
inputPath = "../../TestFiles/"
outputPath = "../../TestFiles/Output/"

def main():
    # The first step in every application using PDFNet is to initialize the 
    # library. The library is usually initialized only once, but calling 
    # Initialize() multiple times is also fine.
    PDFNet.Initialize(LicenseKey)
    
    PDFNet.AddResourceSearchPath("../../../PDFNetC/Lib/")

    if not StructuredOutputModule.IsModuleAvailable():
        print("")
        print("Unable to run the sample: PDFTron SDK Structured Output module not available.")
        print("-----------------------------------------------------------------------------")
        print("The Structured Output module is an optional add-on, available for download")
        print("at https://docs.apryse.com/core/info/modules/. If you have already")
        print("downloaded this module, ensure that the SDK is able to find the required files")
        print("using the PDFNet::AddResourceSearchPath() function.")
        print("")
        return

    #-----------------------------------------------------------------------------------

    try:
        # Convert PDF document to Word
        print("Converting PDF to Word")

        outputFile = outputPath + "paragraphs_and_tables.docx"

        Convert.ToWord(inputPath + "paragraphs_and_tables.pdf", outputFile)

        print("Result saved in " + outputFile)
    except Exception as e:
        print("Unable to convert PDF document to Word, error: " + str(e))

    #-----------------------------------------------------------------------------------

    try:
        # Convert PDF document to Word with options
        print("Converting PDF to Word with options")

        outputFile = outputPath + "paragraphs_and_tables_first_page.docx"

        wordOutputOptions = WordOutputOptions()

        # Convert only the first page
        wordOutputOptions.SetPages(1, 1)

        Convert.ToWord(inputPath + "paragraphs_and_tables.pdf", outputFile, wordOutputOptions)

        print("Result saved in " + outputFile)
    except Exception as e:
        print("Unable to convert PDF document to Word, error: " + str(e))

    #-----------------------------------------------------------------------------------

    try:
        # Convert PDF document to Excel
        print("Converting PDF to Excel")

        outputFile = outputPath + "paragraphs_and_tables.xlsx"

        Convert.ToExcel(inputPath + "paragraphs_and_tables.pdf", outputFile)

        print("Result saved in " + outputFile)
    except Exception as e:
        print("Unable to convert PDF document to Excel, error: " + str(e))

    #-----------------------------------------------------------------------------------

    try:
        # Convert PDF document to Excel with options
        print("Converting PDF to Excel with options")

        outputFile = outputPath + "paragraphs_and_tables_second_page.xlsx"

        excelOutputOptions = ExcelOutputOptions()

        # Convert only the second page
        excelOutputOptions.SetPages(2, 2)

        Convert.ToExcel(inputPath + "paragraphs_and_tables.pdf", outputFile, excelOutputOptions)

        print("Result saved in " + outputFile)
    except Exception as e:
        print("Unable to convert PDF document to Excel, error: " + str(e))

    #-----------------------------------------------------------------------------------

    try:
        # Convert PDF document to PowerPoint
        print("Converting PDF to PowerPoint")

        outputFile = outputPath + "paragraphs_and_tables.pptx"

        Convert.ToPowerPoint(inputPath + "paragraphs_and_tables.pdf", outputFile)

        print("Result saved in " + outputFile)
    except Exception as e:
        print("Unable to convert PDF document to PowerPoint, error: " + str(e))

    #-----------------------------------------------------------------------------------

    try:
        # Convert PDF document to PowerPoint with options
        print("Converting PDF to PowerPoint with options")

        outputFile = outputPath + "paragraphs_and_tables_first_page.pptx"

        powerPointOutputOptions = PowerPointOutputOptions()

        # Convert only the first page
        powerPointOutputOptions.SetPages(1, 1)

        Convert.ToPowerPoint(inputPath + "paragraphs_and_tables.pdf", outputFile, powerPointOutputOptions)

        print("Result saved in " + outputFile)
    except Exception as e:
        print("Unable to convert PDF document to PowerPoint, error: " + str(e))

    #-----------------------------------------------------------------------------------

    PDFNet.Terminate()
    print("Done.")
    
if __name__ == '__main__':
    main()
```

{% endcode %}
{% endtab %}

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

```ruby
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

require '../../../PDFNetC/Lib/PDFNetRuby'
include PDFNetRuby
require '../../LicenseKey/RUBY/LicenseKey'

$stdout.sync = true

#---------------------------------------------------------------------------------------
# The following sample illustrates how to use the PDF.Convert utility class to convert 
# documents and files to Word, Excel and PowerPoint.
#
# The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
# and other documents into Word, Excel, PowerPoint and HTML format.
#
# The PDFTron SDK Structured Output module can be downloaded from
# https://docs.apryse.com/core/info/modules/
#
# Please contact us if you have any questions.
#---------------------------------------------------------------------------------------

# Relative path to the folder containing the test files.
$inputPath = "../../TestFiles/"
$outputPath = "../../TestFiles/Output/"
	
def main()
	# The first step in every application using PDFNet is to initialize the 
	# library. The library is usually initialized only once, but calling 
	# Initialize() multiple times is also fine.
	PDFNet.Initialize(PDFTronLicense.Key)

	PDFNet.AddResourceSearchPath("../../../PDFNetC/Lib/");

	if !StructuredOutputModule.IsModuleAvailable() then
		puts ""
		puts "Unable to run the sample: PDFTron SDK Structured Output module not available."
		puts "-----------------------------------------------------------------------------"
		puts "The Structured Output module is an optional add-on, available for download"
		puts "at https://docs.apryse.com/core/info/modules/. If you have already"
		puts "downloaded this module, ensure that the SDK is able to find the required files"
		puts "using the PDFNet::AddResourceSearchPath() function."
		puts ""
		return
	end
	
	#-----------------------------------------------------------------------------------

	begin
		# Convert PDF document to Word
		puts "Converting PDF to Word"

		$outputFile = $outputPath + "paragraphs_and_tables.docx"

		Convert.ToWord($inputPath + "paragraphs_and_tables.pdf", $outputFile)

		puts "Result saved in " + $outputFile
	rescue => error
		puts "Unable to convert PDF document to Word, error: " + error.message
	end

	#-----------------------------------------------------------------------------------
	
	begin
		# Convert PDF document to Word with options
		puts "Converting PDF to Word with options"

		$outputFile = $outputPath + "paragraphs_and_tables_first_page.docx"

		$wordOutputOptions = Convert::WordOutputOptions.new()

		# Convert only the first page
		$wordOutputOptions.SetPages(1, 1);

		Convert.ToWord($inputPath + "paragraphs_and_tables.pdf", $outputFile, $wordOutputOptions)
		puts "Result saved in " + $outputFile
	rescue => error
		puts "Unable to convert PDF document to Word, error: " + error.message
	end

	#-----------------------------------------------------------------------------------

	begin
		# Convert PDF document to Excel
		puts "Converting PDF to Excel"

		$outputFile = $outputPath + "paragraphs_and_tables.xlsx"

		Convert.ToExcel($inputPath + "paragraphs_and_tables.pdf", $outputFile)

		puts "Result saved in " + $outputFile
	rescue => error
		puts "Unable to convert PDF document to Excel, error: " + error.message
	end

	#-----------------------------------------------------------------------------------
	
	begin
		# Convert PDF document to Excel with options
		puts "Converting PDF to Excel with options"

		$outputFile = $outputPath + "paragraphs_and_tables_second_page.xlsx"

		$excelOutputOptions = Convert::ExcelOutputOptions.new()

		# Convert only the second page
		$excelOutputOptions.SetPages(2, 2);

		Convert.ToExcel($inputPath + "paragraphs_and_tables.pdf", $outputFile, $excelOutputOptions)
		puts "Result saved in " + $outputFile
	rescue => error
		puts "Unable to convert PDF document to Excel, error: " + error.message
	end

	#-----------------------------------------------------------------------------------

	begin
		# Convert PDF document to PowerPoint
		puts "Converting PDF to PowerPoint"

		$outputFile = $outputPath + "paragraphs_and_tables.pptx"

		Convert.ToPowerPoint($inputPath + "paragraphs_and_tables.pdf", $outputFile)

		puts "Result saved in " + $outputFile
	rescue => error
		puts "Unable to convert PDF document to PowerPoint, error: " + error.message
	end

	#-----------------------------------------------------------------------------------
	
	begin
		# Convert PDF document to PowerPoint with options
		puts "Converting PDF to PowerPoint with options"

		$outputFile = $outputPath + "paragraphs_and_tables_first_page.pptx"

		$powerPointOutputOptions = Convert::PowerPointOutputOptions.new()

		# Convert only the first page
		$powerPointOutputOptions.SetPages(1, 1);

		Convert.ToPowerPoint($inputPath + "paragraphs_and_tables.pdf", $outputFile, $powerPointOutputOptions)
		puts "Result saved in " + $outputFile
	rescue => error
		puts "Unable to convert PDF document to PowerPoint, error: " + error.message
	end

	#-----------------------------------------------------------------------------------

	PDFNet.Terminate
	puts "Done."
end

main()
```

{% endcode %}
{% endtab %}

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

```vb
'
' Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
'

Imports System
Imports pdftron
Imports pdftron.Common
Imports pdftron.PDF

' The following sample illustrates how to use the PDF:Convert utility Class To convert 
' documents And files to Office.
'
' The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
' and other documents into Word, Excel, PowerPoint and HTML format.
'
' The Apryse SDK Structured Output module can be downloaded from
' https://docs.apryse.com/core/info/modules/
'
' Please contact us if you have any questions.	
'
' Also note that conversion under ASP.NET can be tricky to configure. Please see the following document for advice: 
' http://www.pdftron.com/pdfnet/faq_files/Converting_Documents_in_Windows_Service_or_ASP.NET_Application_using_PDFNet.pdf

Module PDF2OfficeTestVB
    Class Class1
        Shared pdfNetLoader As pdftron.PDFNetLoader = pdftron.PDFNetLoader.Instance()

        Shared Sub New()
        End Sub

        ' Relative path to the folder containing test files.
        Const inputPath As String = "../../../../TestFiles/"
        Const outputPath As String = "../../../../TestFiles/Output/"

        <STAThread>
        Shared Sub Main(ByVal args As String())
            ' The first step in every application using PDFNet Is to initialize the 
            ' library. The library Is usually initialized only once, but calling 
            ' Initialize() multiple times Is also fine.
            PDFNet.Initialize(PDFTronLicense.Key)

            PDFNet.AddResourceSearchPath("../../../../../Lib/")

            If Not StructuredOutputModule.IsModuleAvailable() Then
                Console.WriteLine()
                Console.WriteLine("Unable to run the sample: Apryse SDK Structured Output module not available.")
                Console.WriteLine("-----------------------------------------------------------------------------")
                Console.WriteLine("The Structured Output module is an optional add-on, available for download")
                Console.WriteLine("at https://docs.apryse.com/core/info/modules/. If you have already")
                Console.WriteLine("downloaded this module, ensure that the SDK is able to find the required files")
                Console.WriteLine("using the PDFNet::AddResourceSearchPath() function.")
                Console.WriteLine()
                Return
            End If

            Dim err As Boolean = False

            '//////////////////////////////////////////////////////////////////////////
            '// Word
            '//////////////////////////////////////////////////////////////////////////

            Try
                ' Convert PDF document to Word
                Console.WriteLine("Converting PDF to Word")

                Dim outputFile As String = outputPath & "paragraphs_and_tables.docx"

                pdftron.PDF.Convert.ToWord(inputPath & "paragraphs_and_tables.pdf", outputFile)

                Console.WriteLine("Result saved in " & outputFile)
            Catch e As PDFNetException
                Console.WriteLine("Unable to convert PDF document to Word, error: " & e.Message)
                err = True
            Catch e As Exception
                Console.WriteLine("Unknown Exception, error: ")
                Console.WriteLine(e)
                err = True
            End Try

            '//////////////////////////////////////////////////////////////////////////

            Try
                ' Convert PDF document to Word with options
                Console.WriteLine("Converting PDF to Word with options")

                Dim outputFile As String = outputPath & "paragraphs_and_tables_first_page.docx"

                Dim wordOutputOptions As pdftron.PDF.Convert.WordOutputOptions = New pdftron.PDF.Convert.WordOutputOptions()

                ' Convert only the first page
                wordOutputOptions.SetPages(1, 1)

                pdftron.PDF.Convert.ToWord(inputPath & "paragraphs_and_tables.pdf", outputFile, wordOutputOptions)

                Console.WriteLine("Result saved in " & outputFile)
            Catch e As PDFNetException
                Console.WriteLine("Unable to convert PDF document to Word, error: " & e.Message)
                err = True
            Catch e As Exception
                Console.WriteLine("Unknown Exception, error: ")
                Console.WriteLine(e)
                err = True
            End Try

            '//////////////////////////////////////////////////////////////////////////
            '// Excel
            '//////////////////////////////////////////////////////////////////////////

            Try
                ' Convert PDF document to Excel
                Console.WriteLine("Converting PDF to Excel")

                Dim outputFile As String = outputPath & "paragraphs_and_tables.xlsx"

                pdftron.PDF.Convert.ToExcel(inputPath & "paragraphs_and_tables.pdf", outputFile)

                Console.WriteLine("Result saved in " & outputFile)
            Catch e As PDFNetException
                Console.WriteLine("Unable to convert PDF document to Excel, error: " & e.Message)
                err = True
            Catch e As Exception
                Console.WriteLine("Unknown Exception, error: ")
                Console.WriteLine(e)
                err = True
            End Try

            '//////////////////////////////////////////////////////////////////////////

            Try
                ' Convert PDF document to Excel with options
                Console.WriteLine("Converting PDF to Excel with options")

                Dim outputFile As String = outputPath & "paragraphs_and_tables_second_page.xlsx"

                Dim excelOutputOptions As pdftron.PDF.Convert.ExcelOutputOptions = New pdftron.PDF.Convert.ExcelOutputOptions()

                ' Convert only the second page
                excelOutputOptions.SetPages(2, 2)

                pdftron.PDF.Convert.ToExcel(inputPath & "paragraphs_and_tables.pdf", outputFile, excelOutputOptions)

                Console.WriteLine("Result saved in " & outputFile)
            Catch e As PDFNetException
                Console.WriteLine("Unable to convert PDF document to Excel, error: " & e.Message)
                err = True
            Catch e As Exception
                Console.WriteLine("Unknown Exception, error: ")
                Console.WriteLine(e)
                err = True
            End Try

            '//////////////////////////////////////////////////////////////////////////
            '// PowerPoint
            '//////////////////////////////////////////////////////////////////////////

            Try
                ' Convert PDF document to PowerPoint
                Console.WriteLine("Converting PDF to PowerPoint")

                Dim outputFile As String = outputPath & "paragraphs_and_tables.pptx"

                pdftron.PDF.Convert.ToPowerPoint(inputPath & "paragraphs_and_tables.pdf", outputFile)

                Console.WriteLine("Result saved in " & outputFile)
            Catch e As PDFNetException
                Console.WriteLine("Unable to convert PDF document to PowerPoint, error: " & e.Message)
                err = True
            Catch e As Exception
                Console.WriteLine("Unknown Exception, error: ")
                Console.WriteLine(e)
                err = True
            End Try

            '//////////////////////////////////////////////////////////////////////////

            Try
                ' Convert PDF document to PowerPoint with options
                Console.WriteLine("Converting PDF to PowerPoint with options")

                Dim outputFile As String = outputPath & "paragraphs_and_tables_first_page.pptx"

                Dim powerPointOutputOptions As pdftron.PDF.Convert.PowerPointOutputOptions = New pdftron.PDF.Convert.PowerPointOutputOptions()

                ' Convert only the first page
                powerPointOutputOptions.SetPages(1, 1)

                pdftron.PDF.Convert.ToPowerPoint(inputPath & "paragraphs_and_tables.pdf", outputFile, powerPointOutputOptions)

                Console.WriteLine("Result saved in " & outputFile)
            Catch e As PDFNetException
                Console.WriteLine("Unable to convert PDF document to PowerPoint, error: " & e.Message)
                err = True
            Catch e As Exception
                Console.WriteLine("Unknown Exception, error: ")
                Console.WriteLine(e)
                err = True
            End Try

            '//////////////////////////////////////////////////////////////////////////

            PDFNet.Terminate()
            Console.WriteLine("Done.")
        End Sub
    End Class
End Module
```

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


---

# 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/get-started/samples/pdf2officetest.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.
