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

# WebViewer

World's #1 PDF SDK Library for Web, Mobile, Server, Desktop

These samples shows how to integrate PDFNet WebViewer into any HTML5, Silverlight, or Flash web application. The sample is using 'pdftron.PDF.Convert.ToXod()' to convert/stream PDF, XPS, MS Office, RTF, HTML and other document formats to WebViewer 'pdftron.PDF.Convert.ToXod()' is an optional Add-On to the Core SDK and is part of PDFNet WebViewer Publishing Platform.

{% 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>

void BulkConvertRandomFilesToXod();

//---------------------------------------------------------------------------------------
// The following sample illustrates how to convert PDF, XPS, image, MS Office, and 
// other image document formats to XOD format.
//
// Certain file formats such as PDF, generic XPS, EMF, and raster image formats can 
// be directly converted to XOD. Other formats such as MS Office 
// (Word, Excel, Publisher, Powerpoint, etc) can be directly converted via interop. 
// These types of conversions guarantee optimal output, while preserving important 
// information such as document metadata, intra document links and hyper-links, 
// bookmarks etc. 
//
// In case there is no direct conversion available, PDFNet can still convert from 
// any printable document to XOD using a virtual printer driver. To check 
// if a virtual printer is required use Convert::RequiresPrinter(filename). In this 
// case the installing application must be run as administrator. The manifest for this 
// sample specifies appropriate the UAC elevation. The administrator privileges are 
// not required for direct or interop conversions. 
//
// Please note that PDFNet Publisher (i.e. 'pdftron.PDF.Convert.ToXod') is an
// optionally licensable add-on to PDFNet Core SDK. For details, please see
// https://apryse.com/pricing.
//---------------------------------------------------------------------------------------

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

        int err = 0;
        @try 
        {
            [PTPDFNet Initialize: 0];
            {
                // Sample 1:
                // Directly convert from PDF to XOD.
                [PTConvert ToXod: @"../../TestFiles/newsletter.pdf" out_filename: @"../../TestFiles/Output/from_pdf.xod"];

                // Sample 2:
                // Directly convert from generic XPS to XOD.
                [PTConvert ToXod: @"../../TestFiles/simple-xps.xps" out_filename: @"../../TestFiles/Output/from_xps.xod"];

                // Sample 3:
                // Convert from MS Office (does not require printer driver for Office 2007+)
                // and other document formats to XOD.
                BulkConvertRandomFilesToXod();
            }
        }
        @catch(NSException *e)
        {
            NSLog(@"%@", e.reason);
            err = 1;
        }
        
        NSLog(@"Done.");
        [PTPDFNet Terminate: 0];
        return err;
    }
}



void BulkConvertRandomFilesToXod()
{
    
    NSArray* testFiles = @[@"butterfly.png", @"numbered.pdf", @"dice.jpg", @"simple-xps.xps"];

    NSString *inputPath = @"../../TestFiles/";
    NSString *outputPath = @"../../TestFiles/Output/";
    
    int err = 0;

    for(NSString* testFile in testFiles)
    {
        @try
        {
            NSString* outputFileName = [[[testFile lastPathComponent] stringByDeletingPathExtension] stringByAppendingPathExtension:@"xod"];
            NSString *inputFilePath = [inputPath stringByAppendingPathComponent: testFile];
            NSString *outputFilePath = [outputPath stringByAppendingPathComponent:outputFileName];
            [PTConvert ToXod: inputFilePath out_filename: outputFilePath];
            NSLog(@"Converted file: %@ to: %@", testFile, outputFileName);
        }
        @catch(NSException *e)
        {
            NSLog(@"Unable to convert file %@", testFile);
            NSLog(@"%@", e.reason);
            err = 1;
        }
    }

    if( err ) {
        NSLog(@"ConvertFile failed");
    }
    else {
        NSLog(@"ConvertFile succeeded");
    }
}
```

{% endcode %}
{% endtab %}

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

```swift
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

import PDFNet
import Foundation

//---------------------------------------------------------------------------------------
// The following sample illustrates how to convert PDF, XPS, image, MS Office, and
// other image document formats to XOD format.
//
// Certain file formats such as PDF, generic XPS, EMF, and raster image formats can
// be directly converted to XOD. Other formats such as MS Office
// (Word, Excel, Publisher, Powerpoint, etc) can be directly converted via interop.
// These types of conversions guarantee optimal output, while preserving important
// information such as document metadata, intra document links and hyper-links,
// bookmarks etc.
//
// In case there is no direct conversion available, PDFNet can still convert from
// any printable document to XOD using a virtual printer driver. To check
// if a virtual printer is required use Convert::RequiresPrinter(filename). In this
// case the installing application must be run as administrator. The manifest for this
// sample specifies appropriate the UAC elevation. The administrator privileges are
// not required for direct or interop conversions.
//
// Please note that PDFNet Publisher (i.e. 'pdftron.PDF.Convert.ToXod') is an
// optionally licensable add-on to PDFNet Core SDK. For details, please see
// https://apryse.com/pricing.
//---------------------------------------------------------------------------------------

func runWebViewerConvertTest() -> Int {
    return autoreleasepool {
        var err: Int = 0
        
        
        do {
            try PTPDFNet.catchException {
                // Sample 1:
                // Directly convert from PDF to XOD.
                PTConvert.toXod(Bundle.main.path(forResource: "newsletter", ofType: "pdf"), out_filename: URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("from_pdf.xod").path)
                
                // Sample 2:
                // Directly convert from generic XPS to XOD.
                PTConvert.toXod(Bundle.main.path(forResource: "simple-xps", ofType: "xps"), out_filename: URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("from_xps.xod").path)
                
                // Sample 3:
                // Convert from MS Office (does not require printer driver for Office 2007+)
                // and other document formats to XOD.
                BulkConvertRandomFilesToXod()
            }
        } catch let e as NSError {
            print("\(e)")
            err = 1
        }
        
        print("Done.")
        return err
    }
}

func BulkConvertRandomFilesToXod() {
    let testFiles = ["butterfly.png", "numbered.pdf", "dice.jpg", "simple-xps.xps"]
    
    let inputPathURL: URL! = Bundle.main.resourceURL
    let outputPathURL = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])
    
    var err: Int = 0
    for testFile: String in testFiles {
        do {
            try PTPDFNet.catchException {
                let inputFilePath: String = inputPathURL.appendingPathComponent(testFile).path
                let outputFilePath: String = outputPathURL.appendingPathComponent(testFile).appendingPathExtension("xod").path

                PTConvert.toXod(inputFilePath, out_filename: outputFilePath)
                print("Converted file: \(inputFilePath)\n            to: \(outputFilePath)")
            }
        } catch let e as NSError {
            print("Unable to convert file \(testFile)")
            print("\(e)")
            err = 1
        }
    }
    
    if err != 0 {
        print("ConvertFile failed")
    } else {
        print("ConvertFile succeeded")
    }
}
```

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