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

# PDF2OfficeTest

Sample Obj-C code for using Apryse SDK to convert generic PDF documents to Office format.

Sample Obj-C code for using Apryse SDK to programmatically convert generic PDF documents to Word, Excel, PowerPoint. Learn more about our [Obj-C PDF to Office](/core/conversion/convert-to-office.md)

To run this sample, you will need to:

1. [Get started with iOS SDK](/ios/get-started/get-started.md)
2. [Download the Structured Output Module](/core/learn-more/modules.md#structured-output-module)

Learn more about our [Mobile SDK for iOS](/ios/get-started/get-started.md).

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

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

#import <OBJC/PDFNetOBJC.h>
#import <Foundation/Foundation.h>

//---------------------------------------------------------------------------------------
// 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/guides/info/modules
//
// Please contact us if you have any questions.
//---------------------------------------------------------------------------------------

int main (int argc, const char * argv[])
{
    @autoreleasepool {

        NSString *inputPath = @"../../TestFiles/";
        NSString *outputPath = @"../../TestFiles/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.
        [PTPDFNet Initialize: 0];

        int ret = 0;

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

        [PTPDFNet AddResourceSearchPath:@"../../../Lib/"];

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

            return 1;
        }
        
        //------------------------------------------------------------------------
        // Word
        //------------------------------------------------------------------------

        @try {
            // Convert PDF document to Word
            NSLog(@"Converting PDF to Word");

            NSString *inputFile = [inputPath stringByAppendingString:@"paragraphs_and_tables.pdf"];
            NSString *outputFile = [outputPath stringByAppendingString:@"paragraphs_and_tables.docx"];

            // Convert PDF to Word
            [PTConvert ToWord:inputFile out_path:outputFile];

            NSLog(@"Result saved in %@", outputFile);
        }
        @catch (NSException *e) {
            NSLog(@"Exception: %@ - %@\n", e.name, e.reason);
            ret = 1;
        }

        @try {
            // Convert PDF document to Word with options
            NSLog(@"Converting PDF to Word with options");

            NSString *inputFile = [inputPath stringByAppendingString:@"paragraphs_and_tables.pdf"];
            NSString *outputFile = [outputPath stringByAppendingString:@"paragraphs_and_tables_first_page.docx"];

            PTWordOutputOptions *wordOutputOptions = [[PTWordOutputOptions alloc] init];

            // Convert only the first page
            [wordOutputOptions SetPages:1 page_to:1];

            // Convert PDF to Word
            [PTConvert ToWordWithFilename:inputFile out_path:outputFile options:wordOutputOptions];

            NSLog(@"Result saved in %@", outputFile);
        }
        @catch (NSException *e) {
            NSLog(@"Exception: %@ - %@\n", e.name, e.reason);
            ret = 1;
        }

        //------------------------------------------------------------------------
        // Excel
        //------------------------------------------------------------------------

        @try {
            // Convert PDF document to Excel
            NSLog(@"Converting PDF to Excel");

            NSString *inputFile = [inputPath stringByAppendingString:@"paragraphs_and_tables.pdf"];
            NSString *outputFile = [outputPath stringByAppendingString:@"paragraphs_and_tables.xlsx"];

            // Convert PDF to Excel
            [PTConvert ToExcel:inputFile out_path:outputFile];

            NSLog(@"Result saved in %@", outputFile);
        }
        @catch (NSException *e) {
            NSLog(@"Exception: %@ - %@\n", e.name, e.reason);
            ret = 1;
        }

        @try {
            // Convert PDF document to Excel with options
            NSLog(@"Converting PDF to Excel with options");

            NSString *inputFile = [inputPath stringByAppendingString:@"paragraphs_and_tables.pdf"];
            NSString *outputFile = [outputPath stringByAppendingString:@"paragraphs_and_tables_second_page.xlsx"];

            PTExcelOutputOptions *excelOutputOptions = [[PTExcelOutputOptions alloc] init];

            // Convert only the second page
            [excelOutputOptions SetPages:2 page_to:2];

            // Convert PDF to Excel
            [PTConvert ToExcelWithFilename:inputFile out_path:outputFile options:excelOutputOptions];

            NSLog(@"Result saved in %@", outputFile);
        }
        @catch (NSException *e) {
            NSLog(@"Exception: %@ - %@\n", e.name, e.reason);
            ret = 1;
        }

        //------------------------------------------------------------------------
        // PowerPoint
        //------------------------------------------------------------------------

        @try {
            // Convert PDF document to PowerPoint
            NSLog(@"Converting PDF to PowerPoint");

            NSString *inputFile = [inputPath stringByAppendingString:@"paragraphs_and_tables.pdf"];
            NSString *outputFile = [outputPath stringByAppendingString:@"paragraphs_and_tables.pptx"];

            // Convert PDF to PowerPoint
            [PTConvert ToPowerPoint:inputFile out_path:outputFile];

            NSLog(@"Result saved in %@", outputFile);
        }
        @catch (NSException *e) {
            NSLog(@"Exception: %@ - %@\n", e.name, e.reason);
            ret = 1;
        }

        @try {
            // Convert PDF document to PowerPoint with options
            NSLog(@"Converting PDF to PowerPoint with options");

            NSString *inputFile = [inputPath stringByAppendingString:@"paragraphs_and_tables.pdf"];
            NSString *outputFile = [outputPath stringByAppendingString:@"paragraphs_and_tables_first_page.pptx"];

            PTPowerPointOutputOptions *powerPointOutputOptions = [[PTPowerPointOutputOptions alloc] init];

            // Convert only the first page
            [powerPointOutputOptions SetPages:1 page_to:1];

            // Convert PDF to PowerPoint
            [PTConvert ToPowerPointWithFilename:inputFile out_path:outputFile options:powerPointOutputOptions];

            NSLog(@"Result saved in %@", outputFile);
        }
        @catch (NSException *e) {
            NSLog(@"Exception: %@ - %@\n", e.name, e.reason);
            ret = 1;
        }

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

        [PTPDFNet Terminate: 0];
        return ret;
    }
}
```

{% 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/ios/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.
