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

# WebViewer Integration - JavaScript PDF Viewer

These samples shows how to integrate PDFNet WebViewer into any HTML5, Silverlight, or Flash web application. Samples provided in Python, C++, C#, Java, Node.js (JavaScript), PHP, Ruby, Go and VB.

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. Samples provided in Python, C++, C#, Java, Node.js (JavaScript), PHP, Ruby, Go and VB.

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

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

using System;
using System.Drawing;
using System.Drawing.Drawing2D;

using pdftron;
using pdftron.Common;
using pdftron.Filters;
using pdftron.SDF;
using pdftron.PDF;

namespace WebViewerConvertCS
{
	/// <summary>
	/// 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 
	/// </summary>
	class Testfile
	{
		public string inputFile, outputFile;
		public Testfile(string inFile, string outFile)
		{
			inputFile = inFile;
			outputFile = outFile;
		}
	};

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

		static void BulkConvertRandomFilesToXod()
		{
			int err = 0;
			System.Collections.ArrayList testfiles = new System.Collections.ArrayList();
			testfiles.Add(new WebViewerConvertCS.Testfile("simple-powerpoint_2007.pptx", "simple-powerpoint_2007.xod"));
			testfiles.Add(new WebViewerConvertCS.Testfile("simple-word_2007.docx", "simple-word_2007.xod"));
			testfiles.Add(new WebViewerConvertCS.Testfile("butterfly.png", "butterfly.xod"));
			testfiles.Add(new WebViewerConvertCS.Testfile("numbered.pdf", "numbered.xod"));
			testfiles.Add(new WebViewerConvertCS.Testfile("dice.jpg", "dice.xod"));
			testfiles.Add(new WebViewerConvertCS.Testfile("simple-xps.xps", "simple-xps.xod"));

			foreach (Testfile file in testfiles)
			{
				try
				{
					if (pdftron.PDF.Convert.RequiresPrinter(inputPath + file.inputFile))
					{
						Console.WriteLine("Using PDFNet printer to convert file " + file.inputFile);
					}

					pdftron.PDF.Convert.ToXod(inputPath + file.inputFile, outputPath + file.outputFile);
					Console.WriteLine("Converted file: " + file.inputFile + " to: " + file.outputFile);
				}
				catch (PDFNetException e)
				{
					Console.WriteLine("ERROR: on input file " + file.inputFile);
					Console.WriteLine(e.Message);
					err = 1;
				}
			}
			if (err == 1) {
				Console.WriteLine("ConvertFile failed");
			} else {
				Console.WriteLine("ConvertFile succeeded");
			}
		}

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

		/// <summary>
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			PDFNet.Initialize(PDFTronLicense.Key);

			// Sample 1:
			// Directly convert from PDF to XOD.
			pdftron.PDF.Convert.ToXod(inputPath + "newsletter.pdf", outputPath + "from_pdf.xod");

			// Sample 2:
			// Directly convert from generic XPS to XOD.
			pdftron.PDF.Convert.ToXod(inputPath + "simple-xps.xps", outputPath + "from_xps.xod");

			// Sample 3:
			// Convert from MS Office (does not require printer driver for Office 2007+)
			// and other document formats to XOD.
			BulkConvertRandomFilesToXod();
			PDFNet.Terminate();
			Console.WriteLine("Done.");
		}
	}
}
```

{% 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 "../../LicenseKey/CPP/LicenseKey.h"

void BulkConvertRandomFilesToXod();

//---------------------------------------------------------------------------------------
// The following sample illustrates how to convert PDF, XPS, image, MS Office, and 
// other image document formats to XOD.
//
// 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.
//---------------------------------------------------------------------------------------

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

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

int main(int argc, char *argv[])
{	
	int err = 0;
	try 
	{
		PDFNet::Initialize(LicenseKey);
		{
			// Sample 1:
			// Directly convert from PDF to XOD.
			Convert::ToXod(inputPath + "newsletter.pdf", outputPath + "from_pdf.xod");

			// Sample 2:
			// Directly convert from generic XPS to XOD.
			Convert::ToXod(inputPath + "simple-xps.xps", outputPath + "from_xps.xod");

			// Sample 3:
			// Convert from MS Office (does not require printer driver for Office 2007+)
			// and other document formats to XOD.
			BulkConvertRandomFilesToXod();
		}
		PDFNet::Terminate();
	}
	catch(Common::Exception& e)
	{
		std::cout << e << std::endl;
		err = 1;
	}
	catch(...)
	{
		std::cout << "Unknown Exception" << std::endl;
		err = 1;
	}

	cout << "Done.\n";
	return err;
}



typedef struct  
{
	UString inputFile, outputFile;
	bool requiresWindowsPlatform;
} Testfile;

Testfile testfiles[] = 
{
	{"simple-powerpoint_2007.pptx",	"simple-powerpoint_2007.xod", true},
	{"simple-word_2007.docx",	"simple-word_2007.xod",	true},	
	{"butterfly.png",		"butterfly.xod",	false},
	{"numbered.pdf",		"numbered.xod",		false},
	{"dice.jpg",			"dice.xod",		false},
	{"simple-xps.xps",		"simple-xps.xod",		false}
};

void BulkConvertRandomFilesToXod()
{
	int err = 0;
#ifdef _MSC_VER
	if( Convert::Printer::IsInstalled("PDFTron PDFNet") )
	{
		Convert::Printer::SetPrinterName("PDFTron PDFNet");
	}
	else if( !Convert::Printer::IsInstalled() )
	{
		try
		{
			// This will fail if not run as administrator. Harmless if PDFNet 
			// printer already installed
			cout << "Installing printer (requires Windows platform and administrator)\n";
			Convert::Printer::Install();
			cout << "Installed printer " << Convert::Printer::GetPrinterName().ConvertToAscii().c_str() << "\n";
		}
		catch(Common::Exception)
		{
			cout << "Unable to install printer\n";
		}
	}
#endif
	unsigned int ceTestfiles = sizeof( testfiles ) / sizeof ( Testfile );

	for( unsigned int i = 0; i < ceTestfiles; i++ )
	{
#ifndef _MSC_VER
		if( testfiles[i].requiresWindowsPlatform)
		{
			continue;
		}
#endif
		try
		{
			UString inputFile = inputPath + testfiles[i].inputFile;
			UString outputFile = outputPath + testfiles[i].outputFile;
			if( Convert::RequiresPrinter(inputFile) )
			{
				cout << "Using PDFNet printer to convert file " << testfiles[i].inputFile << "\n";
			}
			Convert::ToXod(inputFile, outputFile);
			cout << "Converted file: " << testfiles[i].inputFile << " to: " << testfiles[i].outputFile << "\n";
		}
		catch(Common::Exception& e)
		{
			cout << "Unable to convert file " << testfiles[i].inputFile.ConvertToAscii().c_str() << "\n";
			cout << e << "\n";
			err = 1;
		}
		catch(...)
		{
			cout << "Unknown Exception" << "\n";
			err = 1;
		}
	}

	if( err ) {
		cout << "ConvertFile failed\n";
	}
	else {
		cout << "ConvertFile succeeded\n";
	}

#ifdef _MSC_VER
	if( Convert::Printer::IsInstalled() )
	{
		try 
		{
			cout << "Uninstalling printer (requires Windows platform and administrator)\n";
			Convert::Printer::Uninstall();
			cout << "Uninstalled Printer " << Convert::Printer::GetPrinterName().ConvertToAscii().c_str() << "\n";
		}
		catch (Common::Exception)
		{
			cout << "Unable to uninstall printer\n";
		}
	}
#endif
}
```

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

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

func main(){
    PDFNetInitialize(PDFTronLicense.Key)

    // Sample 1:
    // Directly convert from PDF to XOD.
    ConvertToXod(inputPath + "newsletter.pdf", outputPath + "from_pdf.xod")

    // Sample 2:
    // Directly convert from generic XPS to XOD.
    ConvertToXod(inputPath + "simple-xps.xps", outputPath + "from_xps.xod")

    // Sample 3:
    // Directly convert from PNG to XOD.
    fmt.Println("Converting: " + inputPath + "butterfly.png" + " to: " + outputPath + "butterfly.xod")
    ConvertToXod(inputPath + "butterfly.png", outputPath + "butterfly.xod")

    // Sample 4:
    fmt.Println("Converting: " + inputPath + "numbered.pdf" + " to: " + outputPath + "numbered.xod")
    ConvertToXod(inputPath + "numbered.pdf", outputPath + "numbered.xod")

    // Sample 5:
    // Directly convert from JPG to XOD.
    fmt.Println("Converting: " + inputPath + "dice.jpg" + " to: " + outputPath + "dice.xod")
    ConvertToXod(inputPath + "dice.jpg", outputPath + "dice.xod")

    // Sample 6:
    // Directly convert from generic XPS to XOD.
    fmt.Println("Converting: " + inputPath + "simple-xps.xps" + " to: " + outputPath + "simple-xps.xod")
    ConvertToXod(inputPath + "simple-xps.xps", outputPath + "simple-xps.xod")

    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 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.
//---------------------------------------------------------------------------------------

public class WebViewerConvertTest {
	public WebViewerConvertTest() {

	}

	private class TestFile {
		public String inputFile;
		public String outputFile;
		public boolean requiresWindowsPlatform;

		public TestFile(String inputFile, String outputFile,
				boolean requiresWindowsPlatform) {
			this.inputFile = inputFile;
			this.outputFile = outputFile;
			this.requiresWindowsPlatform = requiresWindowsPlatform;
		}
	}

	public static boolean printerInstalled;
	
	// Relative path to the folder containing test files.
	public static String input_path = "../../TestFiles/";
	public static String output_path = "../../TestFiles/Output/";	
	
	public TestFile[] testFiles = {
			new TestFile("simple-powerpoint_2007.pptx",	"simple-powerpoint_2007.xod", true),
			new TestFile("simple-word_2007.docx", "simple-word_2007.xod", true),
			new TestFile("butterfly.png", "butterfly.xod", false),
			new TestFile("numbered.pdf", "numbered.xod", false),
			new TestFile("dice.jpg", "dice.xod", false),
			new TestFile("simple-xps.xps", "simple-xps.xod", false) };

	public void bulkConvertRandomFilesToXod() {
		int err = 0;
		if(System.getProperty("os.name").startsWith("Windows"))
		{
			try {
				// See if the alternative printer is installed, the PDFNet printer
				// is installed, or if not try to install a printer
				if (ConvertPrinter.isInstalled("PDFTron PDFNet")) {
					ConvertPrinter.setPrinterName("PDFTron PDFNet");
					printerInstalled = true;
					System.out.println("PDFTron PDFNet Printer is already installed");
				} else if (ConvertPrinter.isInstalled()) {
					printerInstalled = true;
					System.out.println("PDFTron PDFNet Printer is already installed");
				} else {
					System.out.println("Installing printer (requires administrator and Windows platform)");
					// This will fail if not run as administrator. Harmless if PDFNet printer already installed
					ConvertPrinter.install();
					System.out.println("Installed printer "	+ ConvertPrinter.getPrinterName());
					printerInstalled = true;
				}
			} catch (PDFNetException e) {
				System.out.println("Unable to install printer, error:");
				System.out.println(e);
			}
		}
		for (int i=0; i<testFiles.length; ++i) {
			TestFile file=testFiles[i];
			try {
				if (Convert.requiresPrinter(file.inputFile)) {
					String osName = System.getProperty("os.name");
					if (osName.indexOf("Windows",0)==-1) {
						continue;
					}
					System.out.println("Using PDFNet printer to convert file " + file.inputFile);
				}
				Convert.toXod(input_path + file.inputFile, output_path + file.outputFile);
				System.out.println("Converted file: " + file.inputFile	+ " to: " + file.outputFile);
			} catch (PDFNetException e) {
				System.out.println("Unable to convert file: " + file.inputFile);
				System.out.println(e.toString());
				err = 1;
			}
		}
		if (err == 1) {
			System.out.println("ConvertFile failed");
		} else {
			System.out.println("ConvertFile succeeded");
		}

		// Uninstall the printer
		if (printerInstalled) {
			try {
				System.out
						.println("Uninstalling printer (requires administrator)");
				ConvertPrinter.uninstall();
				System.out.println("Uninstalled printer "
						+ ConvertPrinter.getPrinterName());
			} catch (PDFNetException e) {
				System.out.println("Unable to uninstall printer, error:");
				System.out.println(e);
			}
		}
	}

	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());

		
		String outputFile;
		printerInstalled = false;

		try {
			// Sample 1:
			// Directly convert from PDF to XOD.
			Convert.toXod(input_path + "newsletter.pdf", output_path+ "from_pdf.xod");

			// Sample 2:
			// Directly convert from generic XPS to XOD.
			Convert.toXod(input_path + "simple-xps.xps", output_path + "from_xps.xod");

			// Sample 3:
			// Convert from MS Office (does not require printer driver for
			// Office 2007+)
			// and other document formats to XOD.
			WebViewerConvertTest test = new WebViewerConvertTest();
			test.bulkConvertRandomFilesToXod();

		} catch (PDFNetException e) {
			System.out.println("Unable to convert file document to XOD, error:");
			System.out.println(e);
		}

		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 convert PDF, XPS, image, MS Office, and 
// other image document formats to XOD.
//
// 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.
//---------------------------------------------------------------------------------------

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

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

  exports.runWebViewerConvertTest = () => {
    const inputPath = '../TestFiles/';
    const outputPath = inputPath + 'Output/';
    const main = async () => {
      try {
        // Sample 1:
        // Directly convert from PDF to XOD.
        await PDFNet.Convert.fileToXod(inputPath + 'newsletter.pdf', outputPath + 'from_pdf.xod');

        // Sample 2:
        // Directly convert from generic XPS to XOD.
        await PDFNet.Convert.fileToXod(inputPath + 'simple-xps.xps', outputPath + 'from_xps.xod');

        // Sample 3:
        // Convert from MS Office (does not require printer driver for Office 2007+)
        // and other document formats to XOD.
        await bulkConvertRandomFilesToXod();
      } catch (err) {
        console.log(err.stack);
      }
    };

    let Testfile = function (inputFile, outputFile, requiresWindowsPlatform) {
      this.inputFile = inputFile;
      this.outputFile = outputFile;
      this.requiresWindowsPlatform = requiresWindowsPlatform;
    }

    const testfiles = [
      new Testfile('simple-powerpoint_2007.pptx', 'simple-powerpoint_2007.xod', true),
      new Testfile('simple-word_2007.docx', 'simple-word_2007.xod', true),
      new Testfile('butterfly.png', 'butterfly.xod', false),
      new Testfile('numbered.pdf', 'numbered.xod', false),
      new Testfile('dice.jpg', 'dice.xod', false),
      new Testfile('simple-xps.xps', 'simple-xps.xod', false),
    ]

    const bulkConvertRandomFilesToXod = async () => {
      let err = 0;
      if (process.platform === 'win32') {
        if (await PDFNet.Convert.printerIsInstalled('PDFTron PDFNet')) {
          await PDFNet.Convert.printerSetPrinterName('PDFTron PDFNet');
        } else if (!(await PDFNet.Convert.printerIsInstalled())) {
          try {
            // This will fail if not run as administrator. Harmless if PDFNet 
            // printer already installed
            console.log('Installing printer (requires Windows platform and administrator)');
            await PDFNet.Convert.printerUninstall();
            console.log('Installed printer ' + await PDFNet.Convert.printerGetPrinterName());
          } catch (exp) {
            console.log('Unable to install printer');
          }
        }
      }

      for (const testfile of testfiles)
      {
        if (process.platform !== 'win32' && testfile.requiresWindowsPlatform) {
          continue;
        }
        try {
          const inputFile = inputPath + testfile.inputFile;
          const outputFile = outputPath + testfile.outputFile;
          if (await PDFNet.Convert.requiresPrinter(inputFile)) {
            console.log('Using PDFNet printer to convert file ' + testfile.inputFile);
          }
          await PDFNet.Convert.fileToXod(inputFile, outputFile);
          console.log('Converted file: ' + testfile.inputFile + ' to: ' + testfile.outputFile);
        } catch (exp) {
          console.log('Unable to convert file ' + testfile.inputFile);
          console.log(exp);
          err = 1;
        }
      }

      if (err) {
        console.log('ConvertFile failed');
      } else {
        console.log('ConvertFile succeeded');
      }

      if (process.platform === 'win32' && await PDFNet.Convert.printerIsInstalled()) {
        try {
          console.log('Uninstalling printer (requires Windows platform and administrator)');
          await PDFNet.Convert.printerUninstall();
          console.log('Uninstalled Printer ' + await PDFNet.Convert.printerGetPrinterName());
        }
        catch (exp)
        {
          console.log('Unable to uninstall printer');
        }
      }
    }

    PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
      console.log('Error: ' + JSON.stringify(error));
    }).then(function () { return PDFNet.shutdown(); });
  };
  exports.runWebViewerConvertTest();
})(exports);
// eslint-disable-next-line spaced-comment
//# sourceURL=WebViewerConvertTest.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 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. 
// 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.
//---------------------------------------------------------------------------------------


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

function main()
{
    global $inputPath, $outputPath, $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.

	// Sample 1:
	// Directly convert from PDF to XOD.
	echo(nl2br("Converting: ".$inputPath."newsletter.pdf"." to ".$outputPath."from_pdf.xod"."\n"));
	Convert::ToXod($inputPath."newsletter.pdf", $outputPath."from_pdf.xod");

	// Sample 2:
	// Directly convert from generic XPS to XOD.
	echo(nl2br("Converting: ".$inputPath."simple-xps.xps"." to ".$outputPath."from_xps.xod"."\n"));
	Convert::ToXod($inputPath."simple-xps.xps", $outputPath."from_xps.xod");

	// Sample 3:
	// Directly convert from PNG to XOD.
	echo(nl2br("Converting: ".$inputPath."butterfly.png"." to ".$outputPath."butterfly.xod"."\n"));
	Convert::ToXod($inputPath."butterfly.png", $outputPath."butterfly.xod");

	// Sample 4:
   	echo(nl2br("Converting: " . $inputPath . "numbered.pdf" . " to: " . $outputPath . "numbered.xod\n"));
	Convert::ToXod($inputPath . "numbered.pdf", $outputPath . "numbered.xod");
	
	// Sample 5:
	// Directly convert from JPG to XOD.
	echo(nl2br("Converting: ".$inputPath."dice.jpg"." to ".$outputPath."dice.xod"."\n"));
	Convert::ToXod($inputPath."dice.jpg", $outputPath."dice.xod");

	// Sample 6:
	// Directly convert from generic XPS to XOD.
   	echo(nl2br("Converting: " . $inputPath . "simple-xps.xps" . " to: " . $outputPath . "simple-xps.xod\n"));
	Convert::ToXod($inputPath . "simple-xps.xps", $outputPath . "simple-xps.xod");
	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
import platform
from PDFNetPython import *

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

#---------------------------------------------------------------------------------------
# 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.
#---------------------------------------------------------------------------------------

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

def main():
    PDFNet.Initialize(LicenseKey)

    # Sample 1:
    # Directly convert from PDF to XOD.
    Convert.ToXod(inputPath + "newsletter.pdf", outputPath + "from_pdf.xod")

    # Sample 2:
    # Directly convert from generic XPS to XOD.
    Convert.ToXod(inputPath + "simple-xps.xps", outputPath + "from_xps.xod")

    # Sample 3:
    # Directly convert from PNG to XOD.
    print("Converting: " + inputPath + "butterfly.png" + " to: " + outputPath + "butterfly.xod")
    Convert.ToXod(inputPath + "butterfly.png", outputPath + "butterfly.xod")

    # Sample 4:
    print("Converting: " + inputPath + "numbered.pdf" + " to: " + outputPath + "numbered.xod")
    Convert.ToXod(inputPath + "numbered.pdf", outputPath + "numbered.xod")

    # Sample 5:
    # Directly convert from JPG to XOD.
    print("Converting: " + inputPath + "dice.jpg" + " to: " + outputPath + "dice.xod")
    Convert.ToXod(inputPath + "dice.jpg", outputPath + "dice.xod")

    # Sample 6:
    # Directly convert from generic XPS to XOD.
    print("Converting: " + inputPath + "simple-xps.xps" + " to: " + outputPath + "simple-xps.xod")
    Convert.ToXod(inputPath + "simple-xps.xps", outputPath + "simple-xps.xod")

    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 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.
#---------------------------------------------------------------------------------------

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

def main()
	PDFNet.Initialize(PDFTronLicense.Key)

    # Sample 1:
    # Directly convert from PDF to XOD.
    Convert.ToXod($inputPath + "newsletter.pdf", $outputPath + "from_pdf.xod")

    # Sample 2:
    # Directly convert from generic XPS to XOD.
    Convert.ToXod($inputPath + "simple-xps.xps", $outputPath + "from_xps.xod")

	# Sample 3:
	# Directly convert from PNG to XOD.
    puts "Converting: " + $inputPath + "butterfly.png" + " to " + $outputPath + "butterfly.xod"
	Convert.ToXod($inputPath + "butterfly.png", $outputPath + "butterfly.xod")

	# Sample 4:
	# Directly convert from PDF to XOD.
    puts "Converting: " + $inputPath + "numbered.pdf" + " to " + $outputPath + "numbered.xod"
	Convert.ToXod($inputPath + "numbered.pdf", $outputPath + "numbered.xod")

	# Sample 5:
	# Directly convert from JPG to XOD.
    puts "Converting: " + $inputPath + "dice.jpg" + " to " + $outputPath + "dice.xod"
	Convert.ToXod($inputPath + "dice.jpg", $outputPath + "dice.xod")
	
	# Sample 6:
	# Directly convert from generic XPS to XOD.
    puts "Converting: " + $inputPath + "simple-xps.xps" + " to " + $outputPath + "simple-xps.xod"
	Convert.ToXod($inputPath + "simple-xps.xps", $outputPath + "simple-xps.xod")
	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 pdftron
Imports pdftron.Common
Imports pdftron.Filters
Imports pdftron.SDF
Imports pdftron.PDF

''' <summary>
''' 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
''' </summary> 
Class Testfile
	Public inputFile As String, outputFile As String
	Public Sub New(ByVal inFile As String, ByVal outFile As String)
		inputFile = inFile
		outputFile = outFile
	End Sub
End Class

Module WebViewerConvertTestVB
	Dim pdfNetLoader As PDFNetLoader
	Sub New()
		pdfNetLoader = pdftron.PDFNetLoader.Instance()
	End Sub
	
	' Relative path to the folder containing test files.
	Dim inputPath As String = "../../../../TestFiles/"
	Dim outputPath As String = "../../../../TestFiles/Output/"

	Private Sub BulkConvertRandomFilesToXod()
		Dim err As Integer = 0
		Dim testfiles As New System.Collections.ArrayList()
		testfiles.Add(New Testfile("simple-powerpoint_2007.pptx", "simple-powerpoint_2007.xod"))
		testfiles.Add(New Testfile("simple-word_2007.docx", "simple-word_2007.xod"))
		testfiles.Add(New Testfile("butterfly.png", "butterfly.xod"))
		testfiles.Add(New Testfile("numbered.pdf", "numbered.xod"))
		testfiles.Add(New Testfile("dice.jpg", "dice.xod"))
		testfiles.Add(New Testfile("simple-xps.xps", "simple-xps.xod"))

		For Each file As Testfile In testfiles
			Try
				If pdftron.PDF.Convert.RequiresPrinter(inputPath + file.inputFile) Then
					Console.WriteLine("Using PDFNet printer to convert file " & file.inputFile)
				End If

				pdftron.PDF.Convert.ToXod(inputPath + file.inputFile, outputPath + file.outputFile)
				Console.WriteLine("Converted file: " & file.inputFile & "to: " & file.outputFile)
			Catch e As PDFNetException
				Console.WriteLine("ERROR: on input file " & file.inputFile)
				Console.WriteLine(e.Message)
				err = 1
			End Try
		Next
		If err = 1 Then
			Console.WriteLine("ConvertFile failed")
		Else
			Console.WriteLine("ConvertFile succeeded")
		End If

	End Sub

	Sub Main()
		PDFNet.Initialize(PDFTronLicense.Key)

		' Sample 1:
		' Directly convert from PDF to XOD.
		pdftron.PDF.Convert.ToXod(inputPath + "newsletter.pdf", outputPath + "from_pdf.xod")

		' Sample 2:
		' Directly convert from generic XPS to XOD.
		pdftron.PDF.Convert.ToXod(inputPath + "simple-xps.xps", outputPath + "from_xps.xod")

		' Sample 3:
		' Convert from MS Office (does not require printer driver for Office 2007+)
		' and other document formats to XOD.
		BulkConvertRandomFilesToXod()
		PDFNet.Terminate()
		Console.WriteLine("Done.")
	End Sub

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/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.
