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

# Convert Between File Types - PDF, SVG, XPS, SVG, TIFF, PNG, JPEG

Sample code for direct, high-quality conversion between PDF, XPS, EMF, SVG, TIFF, PNG, JPEG, and other image formats ('pdftron.PDF.Convert' namespace). The sample also shows how to convert any printab

Sample code to use Apryse Server SDK for direct, high-quality conversion between PDF, XPS, SVG, TIFF, PNG, JPEG, and other image formats ('pdftron.PDF.Convert' namespace); provided in Python, C++, C#, Java, JavaScript, PHP, Ruby, Go and VB. The sample also shows how to convert MS Office files using our built in conversion. Learn more about our [Server SDK](/core/get-started/get-started.md) and [PDF Conversion Library](/core/conversion/conversion.md).

{% 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 ConvertTestCS
{
	/// <summary>
	// The following sample illustrates how to use the PDF::Convert utility class to convert 
	// documents and files to PDF, XPS, or SVG, or EMF. The sample also shows how to convert MS Office files 
	// using our built in conversion.
	//
	// Certain file formats such as XPS, EMF, PDF, and raster image formats can be directly 
	// converted to PDF or XPS. 
	//
	// 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
	/// </summary>
	class Testfile
	{
		public string inputFile, outputFile;
		public Testfile(string inFile, string outFile)
		{
			inputFile = inFile;
			outputFile = outFile;
		}
	};

	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/";

		static bool ConvertSpecificFormats()
		{
			//////////////////////////////////////////////////////////////////////////
			bool err = false;
			try
			{
				using (PDFDoc pdfdoc = new PDFDoc())
				{
					Console.WriteLine("Converting from XPS");

					pdftron.PDF.Convert.FromXps(pdfdoc, inputPath + "simple-xps.xps");
					pdfdoc.Save(outputPath + "xps2pdf v2.pdf", SDFDoc.SaveOptions.e_remove_unused);
					Console.WriteLine("Saved xps2pdf v2.pdf");
				}
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
				err = true;
			}

			//////////////////////////////////////////////////////////////////////////
			try
			{
				using (PDFDoc pdfdoc = new PDFDoc())
				{
					// Add a dictionary
					ObjSet set = new ObjSet();
					Obj options = set.CreateDict();

					// Put options
					options.PutNumber("FontSize", 15);
					options.PutBool("UseSourceCodeFormatting", true);
					options.PutNumber("PageWidth", 12);
					options.PutNumber("PageHeight", 6);

					// Convert from .txt file
					Console.WriteLine("Converting from txt");
					pdftron.PDF.Convert.FromText(pdfdoc, inputPath + "simple-text.txt", options);
					pdfdoc.Save(outputPath + "simple-text.pdf", SDFDoc.SaveOptions.e_remove_unused);
					Console.WriteLine("Saved simple-text.pdf");
				}
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
				err = true;
			}

			//////////////////////////////////////////////////////////////////////////
			try
			{
				using (PDFDoc pdfdoc = new PDFDoc(inputPath + "newsletter.pdf"))
				{
					// Convert PDF document to SVG
					Console.WriteLine("Converting pdfdoc to SVG");
					pdftron.PDF.Convert.ToSvg(pdfdoc, outputPath + "pdf2svg v2.svg");
					Console.WriteLine("Saved pdf2svg v2.svg");
				}
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
				err = true;
			}

			//////////////////////////////////////////////////////////////////////////
			try
			{
				// Convert PNG image to XPS
				Console.WriteLine("Converting PNG to XPS");
				pdftron.PDF.Convert.ToXps(inputPath + "butterfly.png", outputPath + "butterfly.xps");
				Console.WriteLine("Saved butterfly.xps");
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
				err = true;
			}

			
			//////////////////////////////////////////////////////////////////////////
			try
			{
				// Convert PDF document to XPS
				Console.WriteLine("Converting PDF to XPS");
				pdftron.PDF.Convert.ToXps(inputPath + "newsletter.pdf", outputPath + "newsletter.xps");
				Console.WriteLine("Saved newsletter.xps");
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
				err = true;
			}

			//////////////////////////////////////////////////////////////////////////
			try
			{
				// Convert PDF document to HTML
				Console.WriteLine("Converting PDF to HTML");
				pdftron.PDF.Convert.ToHtml(inputPath + "newsletter.pdf", outputPath + "newsletter");
				Console.WriteLine("Saved newsletter as HTML");
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
				err = true;
			}

			//////////////////////////////////////////////////////////////////////////
			try
			{
				// Convert PDF document to EPUB
				Console.WriteLine("Converting PDF to EPUB");
				pdftron.PDF.Convert.ToEpub(inputPath + "newsletter.pdf", outputPath + "newsletter.epub");
				Console.WriteLine("Saved newsletter.epub");
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
				err = true;
			}

			//////////////////////////////////////////////////////////////////////////
			try
			{
				// Convert PDF document to multipage TIFF
				Console.WriteLine("Converting PDF to multipage TIFF");
				pdftron.PDF.Convert.TiffOutputOptions tiff_options = new pdftron.PDF.Convert.TiffOutputOptions();
				tiff_options.SetDPI(200);
				tiff_options.SetDither(true);
				tiff_options.SetMono(true);
				pdftron.PDF.Convert.ToTiff(inputPath + "newsletter.pdf", outputPath + "newsletter.tiff", tiff_options);
				Console.WriteLine("Saved newsletter.tiff");
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
				err = true;
			}

			//////////////////////////////////////////////////////////////////////////
			try
			{
				using (PDFDoc pdfdoc = new PDFDoc())
				{
					// Convert SVG file to PDF
					Console.WriteLine("Converting SVG to PDF");

					pdftron.PDF.Convert.FromSVG(pdfdoc, inputPath + "tiger.svg", null);
					pdfdoc.Save(outputPath + "svg2pdf.pdf", SDFDoc.SaveOptions.e_remove_unused);

					Console.WriteLine("Saved svg2pdf.pdf");
				}
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
				err = true;
			}

			return err;
		}

		static Boolean ConvertToPdfFromFile()
		{
			System.Collections.ArrayList testfiles = new System.Collections.ArrayList();
			testfiles.Add(new ConvertTestCS.Testfile("simple-word_2007.docx", "docx2pdf.pdf"));
			testfiles.Add(new ConvertTestCS.Testfile("simple-powerpoint_2007.pptx", "pptx2pdf.pdf"));
			testfiles.Add(new ConvertTestCS.Testfile("simple-excel_2007.xlsx", "xlsx2pdf.pdf"));
			testfiles.Add(new ConvertTestCS.Testfile("simple-text.txt", "txt2pdf.pdf"));
			testfiles.Add(new ConvertTestCS.Testfile("butterfly.png", "png2pdf.pdf"));
			testfiles.Add(new ConvertTestCS.Testfile("simple-xps.xps", "xps2pdf.pdf"));
			
			bool err = false;

			foreach (Testfile file in testfiles)
			{
				try
				{
					using (pdftron.PDF.PDFDoc pdfdoc = new PDFDoc())
					{
						pdftron.PDF.Convert.Printer.SetMode(pdftron.PDF.Convert.Printer.Mode.e_prefer_builtin_converter);
						pdftron.PDF.Convert.ToPdf(pdfdoc, inputPath + file.inputFile);
						pdfdoc.Save(outputPath + file.outputFile, SDFDoc.SaveOptions.e_linearized);
						Console.WriteLine("Converted file: " + file.inputFile);
						Console.WriteLine("to: " + file.outputFile);
					}
				}
				catch (PDFNetException e)
				{
					Console.WriteLine("ERROR: on input file " + file.inputFile);
					Console.WriteLine(e.Message);
					err = true;
				}
			}

			return err;
		}


		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			PDFNet.Initialize(PDFTronLicense.Key);
			bool err = false;

			err = ConvertToPdfFromFile();
			if (err)
			{
				Console.WriteLine("ConvertFile failed");
			}
			else
			{
				Console.WriteLine("ConvertFile succeeded");
			}

			err = ConvertSpecificFormats();
			if (err)
			{
				Console.WriteLine("ConvertSpecificFormats failed");
			}
			else
			{
				Console.WriteLine("ConvertSpecificFormats succeeded");
			}

			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"

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF::Convert utility class to convert 
// documents and files to PDF, XPS, or SVG. The sample also shows how to convert MS Office files 
// using our built in conversion.
//
// Certain file formats such as XPS, PDF, and raster image formats can be directly 
// converted to PDF or XPS. 

// Please contact us if you have any questions.	
//---------------------------------------------------------------------------------------

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

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

typedef struct  
{
	UString inputFile, outputFile;
}
Testfile;

Testfile testfiles[] = 
{
	{ "simple-word_2007.docx",		"docx2pdf.pdf"},
	{ "simple-powerpoint_2007.pptx",	"pptx2pdf.pdf"},
	{ "simple-excel_2007.xlsx",		"xlsx2pdf.pdf"},
	{ "simple-text.txt",			"txt2pdf.pdf"},
	{ "butterfly.png",			"png2pdf.pdf"},
	{ "simple-xps.xps",			"xps2pdf.pdf"}
};

int ConvertSpecificFormats();  // convert to/from PDF, XPS, SVG
int ConvertToPdfFromFile();	   // convert from a file to PDF automatically

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.
	int err = 0;

	PDFNet::Initialize(LicenseKey);

	// Demonstrate Convert::ToPdf
	err = ConvertToPdfFromFile();
	if (err)
	{
		cout << "ConvertFile failed" << endl;
	}
	else
	{
		cout << "ConvertFile succeeded" << endl;
	}

	// Demonstrate Convert::[FromXps, ToSVG, ToXPS]
	err = ConvertSpecificFormats();
	if (err)
	{
		cout << "ConvertSpecificFormats failed" << endl;
	}
	else
	{
		cout << "ConvertSpecificFormats succeeded" << endl;
	}

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

int ConvertToPdfFromFile()
{
	int ret = 0;

	unsigned int ceTestfiles = sizeof (testfiles) / sizeof (Testfile);

	for (unsigned int i = 0; i < ceTestfiles; i++)
	{

		try
		{
			PDFDoc pdfdoc;
			UString inputFile = inputPath + testfiles[i].inputFile;
			UString outputFile = outputPath + testfiles[i].outputFile;

			Convert::Printer::SetMode(Convert::Printer::e_prefer_builtin_converter);
			Convert::ToPdf(pdfdoc, inputFile);
			pdfdoc.Save(outputFile, SDF::SDFDoc::e_linearized, NULL);
			cout << "Converted file: " << testfiles[i].inputFile << endl << "to: " << testfiles[i].outputFile << endl;
		}
		catch (Common::Exception& e)
		{
			cout << "Unable to convert file " << testfiles[i].inputFile.ConvertToAscii().c_str() << endl;
			cout << e << endl;
			ret = 1;
		}
		catch (...)
		{
			cout << "Unknown Exception" << endl;
			ret = 1;
		}
	}

	return ret;
}

int ConvertSpecificFormats()
{
	//////////////////////////////////////////////////////////////////////////
	int ret = 0;
	try
	{
		PDFDoc pdfdoc;

		cout << "Converting from XPS" << endl;
		Convert::FromXps(pdfdoc, inputPath + "simple-xps.xps");
		pdfdoc.Save(outputPath + "xps2pdf v2.pdf", SDF::SDFDoc::e_remove_unused, NULL);
		cout << "Saved xps2pdf v2.pdf" << endl;
	}
	catch (Common::Exception& e)
	{
		cout << e << endl;
		ret = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	//////////////////////////////////////////////////////////////////////////
	try
	{
		PDFDoc pdfdoc;

		// Add a dictionary
		SDF::ObjSet set;
		SDF::Obj options = set.CreateDict();

		// Put options
		options.PutNumber("FontSize", 15);
		options.PutBool("UseSourceCodeFormatting", true);
		options.PutNumber("PageWidth", 12);
		options.PutNumber("PageHeight", 6);

		// Convert from .txt file
		cout << "Converting from txt" << endl;
		Convert::FromText(pdfdoc, inputPath + "simple-text.txt", options);
		pdfdoc.Save(outputPath + "simple-text.pdf", SDF::SDFDoc::e_remove_unused, NULL);
		cout << "Saved simple-text.pdf" << endl;
	}
	catch (Common::Exception& e)
	{
		cout << e << endl;
		ret = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	//////////////////////////////////////////////////////////////////////////
	try
	{
		PDFDoc pdfdoc(inputPath + "newsletter.pdf");

		// Convert PDF document to SVG
		cout << "Converting pdfdoc to SVG" << endl;
		Convert::ToSvg(pdfdoc, outputPath + "pdf2svg v2.svg");
		cout << "Saved pdf2svg v2.svg" << endl;
	}
	catch (Common::Exception& e)
	{
		cout << e << endl;
		ret = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	//////////////////////////////////////////////////////////////////////////
	try
	{
		// Convert PNG image to XPS
		cout << "Converting PNG to XPS" << endl;
		Convert::ToXps(inputPath + "butterfly.png", outputPath + "butterfly.xps");
		cout << "Saved butterfly.xps" << endl;
	}
	catch (Common::Exception& e)
	{
		cout << e << endl;
		ret = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	//////////////////////////////////////////////////////////////////////////
	try
	{
		// Convert PDF document to XPS
		cout << "Converting PDF to XPS" << endl;
		Convert::ToXps(inputPath + "newsletter.pdf", outputPath + "newsletter.xps");
		cout << "Saved newsletter.xps" << endl;
	}
	catch (Common::Exception& e)
	{
		cout << e << endl;
		ret = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	//////////////////////////////////////////////////////////////////////////
	try
	{
		// Convert PDF document to HTML
		cout << "Converting PDF to HTML" << endl;
		Convert::ToHtml(inputPath + "newsletter.pdf", outputPath + "newsletter");
		cout << "Saved newsletter as HTML" << endl;
	}
	catch (Common::Exception& e)
	{
		cout << e << endl;
		ret = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	//////////////////////////////////////////////////////////////////////////
	try
	{
		// Convert PDF document to EPUB
		cout << "Converting PDF to EPUB" << endl;
		Convert::ToEpub(inputPath + "newsletter.pdf", outputPath + "newsletter.epub");
		cout << "Saved newsletter.epub" << endl;
	}
	catch (Common::Exception& e)
	{
		cout << e << endl;
		ret = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	//////////////////////////////////////////////////////////////////////////
	try
	{
		// Convert PDF document to multipage TIFF
		cout << "Converting PDF to multipage TIFF" << endl;
		Convert::TiffOutputOptions tiff_options;
		tiff_options.SetDPI(200);
		tiff_options.SetDither(true);
		tiff_options.SetMono(true);
		Convert::ToTiff(inputPath + "newsletter.pdf", outputPath + "newsletter.tiff", tiff_options);
		cout << "Saved newsletter.tiff" << endl;
	}
	catch (Common::Exception& e)
	{
		cout << e << endl;
		ret = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	//////////////////////////////////////////////////////////////////////////
	try
	{
		PDFDoc pdfdoc;

		// Convert SVG file to PDF
		cout << "Converting SVG to PDF" << endl;

		Convert::FromSVG(pdfdoc, inputPath + "tiger.svg");
		pdfdoc.Save(outputPath + "svg2pdf.pdf", SDF::SDFDoc::e_remove_unused, NULL);

		cout << "Saved svg2pdf.pdf" << endl;
	}
	catch (Common::Exception& e)
	{
		cout << e << endl;
		ret = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	return ret;
}
```

{% 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"
	"runtime"
	. "pdftron"
)

import  "pdftron/Samples/LicenseKey/GO"

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF.Convert utility class to convert 
// documents and files to PDF, XPS, SVG, or EMF.
//
// Certain file formats such as XPS, EMF, PDF, and raster image formats can be directly 
// converted to PDF or XPS. Other formats are converted using a virtual driver. To check 
// if ToPDF (or ToXPS) require that PDFNet printer is installed use Convert.RequiresPrinter(filename). 
// The installing application must be run as administrator. The manifest for this sample 
// specifies appropriate the UAC elevation.
//
// Note: the PDFNet printer is a virtual XPS printer supported on Vista SP1 and Windows 7.
// For Windows XP SP2 or higher, or Vista SP0 you need to install the XPS Essentials Pack (or 
// equivalent redistributables). You can download the XPS Essentials Pack from:
//        http://www.microsoft.com/downloads/details.aspx?FamilyId=B8DCFFDD-E3A5-44CC-8021-7649FD37FFEE&displaylang=en
// Windows XP Sp2 will also need the Microsoft Core XML Services (MSXML) 6.0:
//         http://www.microsoft.com/downloads/details.aspx?familyid=993C0BCF-3BCF-4009-BE21-27E85E1857B1&displaylang=en
//
// Note: Convert.fromEmf and Convert.toEmf will only work on Windows and require GDI+.
//
// 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 ConvertToPdfFromFile() bool{
	testFiles := [][]string{	
	{"simple-word_2007.docx","docx2pdf.pdf", "false"}, 
	{"simple-powerpoint_2007.pptx","pptx2pdf.pdf", "false"}, 
	{"simple-excel_2007.xlsx","xlsx2pdf.pdf", "false"}, 
	{"simple-publisher.pub","pub2pdf.pdf", "true"},
	//{"simple-visio.vsd","vsd2pdf.pdf}, // requires Microsoft Office Visio 
	{"simple-text.txt","txt2pdf.pdf", "false"}, 
	{"simple-rtf.rtf","rtf2pdf.pdf", "true"}, 
	{"butterfly.png","png2pdf.pdf", "false"}, 
	{"simple-emf.emf","emf2pdf.pdf", "true"}, 
	{"simple-xps.xps","xps2pdf.pdf", "false"}, 
	//{"simple-webpage.mht","mht2pdf.pdf", true}, 
	{"simple-webpage.html","html2pdf.pdf", "true"}}

    ret := false

    if runtime.GOOS == "windows" {
        if PrinterIsInstalled("PDFTron PDFNet"){
			PrinterSetPrinterName("PDFTron PDFNet")
        }else if ! PrinterIsInstalled(){
			fmt.Println("Installing printer (requires Windows platform and administrator)")
			PrinterInstall()
			fmt.Println("Installed printer " + PrinterGetPrinterName())
		}
	}

	for _, testfile := range testFiles {
	    if runtime.GOOS != "windows" {
            if testfile[2] == "true" {
                continue
			}
		}
        pdfdoc := NewPDFDoc()
        inputFile := testfile[0]
        outputFile := testfile[1]
        if ConvertRequiresPrinter(inputPath + inputFile){
            fmt.Println("Using PDFNet printer to convert file " + inputFile)
		}
        ConvertToPdf(pdfdoc, inputPath + inputFile)
        pdfdoc.Save(outputPath + outputFile, uint(SDFDocE_compatibility))
        pdfdoc.Close()
        fmt.Println("Converted file: " + inputFile + "\nto: " + outputFile)
	}
    return ret
}

func ConvertSpecificFormats() bool{
	ret := false
    // Start with a PDFDoc to collect the converted documents
    pdfdoc := NewPDFDoc()
    s1 := inputPath + "simple-xps.xps"
    // Convert the XPS document to PDF
    fmt.Println("Converting from XPS")
    ConvertFromXps(pdfdoc, s1)
    outputFile := "xps2pdf v2.pdf"
    pdfdoc.Save(outputPath + outputFile, uint(SDFDocE_remove_unused))
    fmt.Println("Saved " + outputFile)
        
    // Convert the EMF document to PDF
	if runtime.GOOS == "windows" {
		s1 = inputPath + "simple-emf.emf"
		fmt.Println("Converting from EMF")
		ConvertFromEmf(pdfdoc, s1)
		outputFile = "emf2pdf v2.pdf"
		pdfdoc.Save(outputPath + outputFile, uint(SDFDocE_remove_unused))
		fmt.Println("Saved " + outputFile)
	}

	// Convert the TXT document to PDF
	set :=  NewObjSet()
	options := set.CreateDict()
	// Put options
	options.PutNumber("FontSize", 15)
	options.PutBool("UseSourceCodeFormatting", true)
	options.PutNumber("PageWidth", 12)
	options.PutNumber("PageHeight", 6)
	s1 = inputPath + "simple-text.txt"
	fmt.Println("Converting from txt")
	ConvertFromText(pdfdoc, s1)
	outputFile = "simple-text.pdf"
	pdfdoc.Save(outputPath + outputFile, uint(SDFDocE_remove_unused))
	fmt.Println("Saved " + outputFile)
        
	// Convert the two page PDF document to SVG
	outputFile = "pdf2svg v2.svg"
	pdfdoc = NewPDFDoc(inputPath + "newsletter.pdf")
	fmt.Println("Converting pdfdoc to SVG")
	ConvertToSvg(pdfdoc, outputPath + outputFile)
	fmt.Println("Saved " + outputFile)
        
	// Convert the PNG image to XPS
	fmt.Println("Converting PNG to XPS")
	outputFile = "butterfly.xps"
	ConvertToXps(inputPath + "butterfly.png", outputPath +outputFile)
	fmt.Println("Saved " + outputFile)
            
	// Convert PDF document to XPS
	fmt.Println("Converting PDF to XPS")
	outputFile = "newsletter.xps"
	ConvertToXps(inputPath + "newsletter.pdf", outputPath + outputFile)
	fmt.Println("Saved " + outputFile)
        
	// Convert PDF document to HTML
	fmt.Println("Converting PDF to HTML")
	outputFile = "newsletter"
	ConvertToHtml(inputPath + "newsletter.pdf", outputPath + outputFile)
	fmt.Println("Saved newsletter as HTML")

	// Convert PDF document to EPUB
	fmt.Println("Converting PDF to EPUB")
	outputFile = "newsletter.epub"
	ConvertToEpub(inputPath + "newsletter.pdf", outputPath + outputFile)
	fmt.Println("Saved " + outputFile)

	fmt.Println("Converting PDF to multipage TIFF")
	tiffOptions := NewTiffOutputOptions()
	tiffOptions.SetDPI(200)
	tiffOptions.SetDither(true)
	tiffOptions.SetMono(true)
	ConvertToTiff(inputPath + "newsletter.pdf", outputPath + "newsletter.tiff", tiffOptions)
	fmt.Println("Saved newsletter.tiff")

    return ret
}

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)

    // Demonstrate Convert.ToPdf and Convert.Printer
    err := ConvertToPdfFromFile()
    if err{
		fmt.Println("ConvertFile failed")
	}else{
		fmt.Println("ConvertFile succeeded")
	}
    // Demonstrate Convert.[FromEmf, FromXps, ToEmf, ToSVG, ToXPS]
    err = ConvertSpecificFormats()
    if err{
		fmt.Println("ConvertSpecificFormats failed")
	}else{
		fmt.Println("ConvertSpecificFormats succeeded")
	}
	if runtime.GOOS == "windows" {
        fmt.Println("Uninstalling printer (requires Windows platform and administrator)")
        PrinterUninstall()
        fmt.Println("Uninstalled printer " + PrinterGetPrinterName())
	}
    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.*;
import com.pdftron.sdf.Obj;
import com.pdftron.sdf.ObjSet;
import com.pdftron.sdf.SDFDoc;
import java.util.ArrayList;
//---------------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF::Convert utility class to convert 
// documents and files to PDF, XPS, or SVG, or EMF. The sample also shows how to convert MS Office files 
// using our built in conversion.
//
// Certain file formats such as XPS, EMF, PDF, and raster image formats can be directly 
// converted to PDF or XPS. 
//
// Please contact us if you have any questions.	
//---------------------------------------------------------------------------------------
class Testfile
{
	public String inputFile, outputFile;
	public Testfile(String inFile, String outFile)
	{
		inputFile = inFile;
		outputFile = outFile;
	}
}

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

	static boolean ConvertSpecificFormats()
	{
		//////////////////////////////////////////////////////////////////////////
		boolean err = false;
		try (PDFDoc pdfdoc = new PDFDoc())
		{

			System.out.println("Converting from XPS");

			Convert.fromXps(pdfdoc, inputPath + "simple-xps.xps");
			pdfdoc.save(outputPath + "xps2pdf v2.pdf", SDFDoc.SaveMode.REMOVE_UNUSED, null);
			System.out.println("Saved xps2pdf v2.pdf");
		}
		catch (PDFNetException e)
		{
			System.out.println(e);
			err = true;
		}

		//////////////////////////////////////////////////////////////////////////
		try (PDFDoc pdfdoc = new PDFDoc())
		{
			// add a dictionary
			ObjSet set = new ObjSet();
			Obj options = set.createDict();

			// Put options
			options.putNumber("FontSize", 15);
			options.putBool("UseSourceCodeFormatting", true);
			options.putNumber("PageWidth", 12);
			options.putNumber("PageHeight", 6);

			// Convert from .txt file
			System.out.println("Converting from txt");
			Convert.fromText(pdfdoc, inputPath + "simple-text.txt", options);
			pdfdoc.save(outputPath + "simple-text.pdf", SDFDoc.SaveMode.REMOVE_UNUSED, null);
			System.out.println("Saved simple-text.pdf");
		}
		catch (PDFNetException e)
		{
			System.out.println(e);
			err = true;
		}
		
		//////////////////////////////////////////////////////////////////////////
		try (PDFDoc pdfdoc = new PDFDoc(inputPath + "newsletter.pdf"))
		{
			// Convert PDF document to SVG
			System.out.println("Converting pdfdoc to SVG");
			Convert.toSvg(pdfdoc, outputPath + "pdf2svg v2.svg");
			System.out.println("Saved pdf2svg v2.svg");
		}
		catch (PDFNetException e)
		{
			System.out.println(e);
			err = true;
		}

		//////////////////////////////////////////////////////////////////////////
		try
		{
			// Convert PNG image to XPS
			System.out.println("Converting PNG to XPS");
			Convert.toXps(inputPath + "butterfly.png", outputPath + "butterfly.xps");
			System.out.println("Saved butterfly.xps");
		}
		catch (PDFNetException e)
		{
			System.out.println(e);
			err = true;
		}

		//////////////////////////////////////////////////////////////////////////
		try
		{
			// Convert PDF document to XPS
			System.out.println("Converting PDF to XPS");
			Convert.toXps(inputPath + "newsletter.pdf", outputPath + "newsletter.xps");
			System.out.println("Saved newsletter.xps");
		}
		catch (PDFNetException e)
		{
			System.out.println(e);
			err = true;
		}

		//////////////////////////////////////////////////////////////////////////
		try
		{
			// Convert PDF document to HTML
			System.out.println("Converting PDF to HTML");
			Convert.toHtml(inputPath + "newsletter.pdf", outputPath + "newsletter");
			System.out.println("Saved newsletter as HTML");
		}
		catch (PDFNetException e)
		{
			System.out.println(e);
			err = true;
		}

		//////////////////////////////////////////////////////////////////////////
		try
		{
			// Convert PDF document to EPUB
			System.out.println("Converting PDF to EPUB");
			Convert.toEpub(inputPath + "newsletter.pdf", outputPath + "newsletter.epub");
			System.out.println("Saved newsletter.epub");
		}
		catch (PDFNetException e)
		{
			System.out.println(e);
			err = true;
		}

		//////////////////////////////////////////////////////////////////////////
		try
		{
			// Convert PDF document to multipage TIFF
			System.out.println("Converting PDF to multipage TIFF");
			Convert.TiffOutputOptions tiff_options = new Convert.TiffOutputOptions();
			tiff_options.setDPI(200);
			tiff_options.setDither(true);
			tiff_options.setMono(true);
			Convert.toTiff(inputPath + "newsletter.pdf", outputPath + "newsletter.tiff", tiff_options);
			System.out.println("Saved newsletter.tiff");
		}
		catch (PDFNetException e)
		{
			System.out.println(e);
			err = true;
		}

		//////////////////////////////////////////////////////////////////////////
		try (PDFDoc pdfdoc = new PDFDoc())
		{
			// Convert SVG file to PDF
			System.out.println("Converting SVG to PDF");
			Convert.fromSVG(pdfdoc, inputPath + "tiger.svg", null);
			pdfdoc.save(outputPath + "svg2pdf.pdf", SDFDoc.SaveMode.REMOVE_UNUSED, null);

			System.out.println("Saved svg2pdf.pdf");
		}
		catch (PDFNetException e)
		{
			System.out.println(e);
			err = true;
		}

		return err;
	}

	static boolean ConvertToPdfFromFile()
	{
		ArrayList<Testfile> testfiles = new ArrayList<Testfile>();
		testfiles.add(new Testfile("simple-word_2007.docx", "docx2pdf.pdf"));
		testfiles.add(new Testfile("simple-powerpoint_2007.pptx", "pptx2pdf.pdf"));
		testfiles.add(new Testfile("simple-excel_2007.xlsx", "xlsx2pdf.pdf"));
		testfiles.add(new Testfile("simple-text.txt", "txt2pdf.pdf"));
		testfiles.add(new Testfile("butterfly.png", "png2pdf.pdf"));
		testfiles.add(new Testfile("simple-xps.xps", "xps2pdf.pdf"));

		boolean err = false;
		
		for (Testfile file : testfiles)
		{
			try (PDFDoc pdfdoc = new PDFDoc())
			{
				//use built in converter
				ConvertPrinter.setMode(ConvertPrinter.e_convert_printer_prefer_builtin_converter);
				Convert.toPdf(pdfdoc, inputPath + file.inputFile);
				pdfdoc.save(outputPath + file.outputFile, SDFDoc.SaveMode.LINEARIZED, null);
				System.out.println("Converted file: " + file.inputFile);
				System.out.println("to: " + file.outputFile);
			}
			catch (PDFNetException e)
			{
				System.out.println("ERROR: on input file " + file.inputFile);
				System.out.println(e);
				err = true;
			}
		}

		return err;
	}

	/// <summary>
	/// The main entry point for the application.
	/// </summary>
	public static void main(String[] args) 
	{
		PDFNet.initialize(PDFTronLicense.Key());
		boolean err = false;

		err = ConvertToPdfFromFile();
		if (err)
		{
			System.out.println("ConvertFile failed");
		}
		else
		{
			System.out.println("ConvertFile succeeded");
		}

		err = ConvertSpecificFormats();
		if (err)
		{
			System.out.println("ConvertSpecificFormats failed");
		}
		else
		{
			System.out.println("ConvertSpecificFormats succeeded");
		}

		System.out.println("Done.");

		PDFNet.terminate();
	}

}
```

{% 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 PDF, XPS, or SVG, or EMF. The sample also shows how to convert MS Office files 
// using our built in conversion.
//
// Certain file formats such as XPS, EMF, PDF, and raster image formats can be directly 
// converted to PDF or XPS. 
//
// Please contact us if you have any questions.	
//---------------------------------------------------------------------------------------

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

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

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

  const testfiles = [
    new Testfile('simple-word_2007.docx', 'docx2pdf.pdf'),
    new Testfile('simple-powerpoint_2007.pptx', 'pptx2pdf.pdf'),
    new Testfile('simple-excel_2007.xlsx', 'xlsx2pdf.pdf'),
    new Testfile('simple-text.txt', 'txt2pdf.pdf'),
    new Testfile('butterfly.png', 'png2pdf.pdf'),
    new Testfile('simple-xps.xps', 'xps2pdf.pdf'),
  ]

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

  exports.runConvertTest = () => {

    const main = async () => {
      try {
        await convertToPdfFromFile();
        console.log('ConvertFile succeeded');
      } catch (err) {
        console.log('ConvertFile failed');
        console.log(err);
      }

      try {
        await convertSpecificFormats();
        console.log('ConvertSpecificFormats succeeded');
      } catch (err) {
        console.log('ConvertSpecificFormats failed');
        console.log(err);
      }

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

    const convertToPdfFromFile = async () => {

      for (const testfile of testfiles) {

        try {
          const pdfdoc = await PDFNet.PDFDoc.create();
          await pdfdoc.initSecurityHandler();
          const inputFile = inputPath + testfile.inputFile;
          const outputFile = outputPath + testfile.outputFile;
          await PDFNet.Convert.printerSetMode(PDFNet.Convert.PrinterMode.e_prefer_builtin_converter);
          await PDFNet.Convert.toPdf(pdfdoc, inputFile);
          await pdfdoc.save(outputFile, PDFNet.SDFDoc.SaveOptions.e_linearized);
          console.log('Converted file: ' + testfile.inputFile + '\nto: ' + testfile.outputFile);
        } catch (err) {
          console.log('Unable to convert file ' + testfile.inputFile);
          console.log(err);
        }
      }
    };

    const convertSpecificFormats = async () => {
      try {
        const pdfdoc = await PDFNet.PDFDoc.create();
        await pdfdoc.initSecurityHandler();

        console.log('Converting from XPS');
        await PDFNet.Convert.fromXps(pdfdoc, inputPath + 'simple-xps.xps');
        await pdfdoc.save(outputPath + 'xps2pdf v2.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
        console.log('Saved xps2pdf v2.pdf');
      } catch (err) {
        console.log(err);
      }


      try {
        const pdfdoc = await PDFNet.PDFDoc.create();
        await pdfdoc.initSecurityHandler();

        // Add a dictionary
        const set = await PDFNet.ObjSet.create();
        const options = await set.createDict();

        // Put options
        options.putNumber('FontSize', 15);
        options.putBool('UseSourceCodeFormatting', true);
        options.putNumber('PageWidth', 12);
        await options.putNumber('PageHeight', 6);

        // Convert from .txt file
        console.log('Converting from txt');
        await PDFNet.Convert.fromText(pdfdoc, inputPath + 'simple-text.txt', options);
        await pdfdoc.save(outputPath + 'simple-text.pdf', PDFNet.SDFDoc.SaveOptions.e_remove_unused);
        console.log('Saved simple-text.pdf');
      } catch (err) {
        console.log(err);
      }

      try {
        const pdfdoc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
        await pdfdoc.initSecurityHandler();

        // Convert PDF document to SVG
        console.log('Converting pdfdoc to SVG');
        await PDFNet.Convert.docToSvg(pdfdoc, outputPath + 'pdf2svg v2.svg');
        console.log('Saved pdf2svg v2.svg');
      } catch (err) {
        console.log(err);
      }

      try {
        // Convert PNG image to XPS
        console.log('Converting PNG to XPS');
        await PDFNet.Convert.fileToXps(inputPath + 'butterfly.png', outputPath + 'butterfly.xps');
        console.log('Saved butterfly.xps');
      } catch (err) {
        console.log(err);
      }


      try {
        // Convert PDF document to XPS
        console.log('Converting PDF to XPS');
        await PDFNet.Convert.fileToXps(inputPath + 'newsletter.pdf', outputPath + 'newsletter.xps');
        console.log('Saved newsletter.xps');
      } catch (err) {
        console.log(err);
      }

      try {
        // Convert PDF document to HTML
        console.log('Converting PDF to HTML');
        await PDFNet.Convert.fileToHtml(inputPath + 'newsletter.pdf', outputPath + 'newsletter');
        console.log('Saved newsletter as HTML');
      } catch (err) {
        console.log(err);
      }

      try {
        // Convert PDF document to EPUB
        console.log('Converting PDF to EPUB');
        await PDFNet.Convert.fileToEpub(inputPath + 'newsletter.pdf', outputPath + 'newsletter.epub');
        console.log('Saved newsletter.epub');
      } catch (err) {
        console.log(err);
      }

      try {
        // Convert PDF document to multipage TIFF
        console.log('Converting PDF to multipage TIFF');
        const tiff_options = new PDFNet.Convert.TiffOutputOptions();
        tiff_options.setDPI(200);
        tiff_options.setDither(true);
        tiff_options.setMono(true);
        
        await PDFNet.Convert.fileToTiff(inputPath + 'newsletter.pdf', outputPath + 'newsletter.tiff', tiff_options);
        console.log('Saved newsletter.tiff');
      } catch (err) {
        console.log(err);
      }

      try {
        const pdfdoc = await PDFNet.PDFDoc.create();
        await pdfdoc.initSecurityHandler();

        // Convert SVG file to PDF
        console.log('Converting SVG to PDF');
        await PDFNet.Convert.fromSVG(pdfdoc, inputPath + 'tiger.svg');
        await pdfdoc.save(outputPath + 'svg2pdf.pdf', PDFNet.SDFDoc.SaveOptions.e_remove_unused);

        console.log('Saved svg2pdf.pdf');
      } catch (err) {
        console.log(err);
      }
    };
    PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
      console.log('Error: ' + JSON.stringify(error));
    }).then(function(){ return PDFNet.shutdown(); });
  };
  exports.runConvertTest();
})(exports);
// eslint-disable-next-line spaced-comment
//# sourceURL=ConvertTest.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 PDF, XPS, or SVG, or EMF. The sample also shows how to convert MS Office files 
// using our built in conversion.
//
// Certain file formats such as XPS, EMF, PDF, and raster image formats can be directly 
// converted to PDF or XPS. 
//
// Please contact us if you have any questions.	
//
// Please contact us if you have any questions.    
//---------------------------------------------------------------------------------------

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


function ConvertSpecificFormats()
{
	global $inputPath, $outputPath;

	$pdfdoc = new PDFDoc();
	$s1 = $inputPath."simple-xps.xps";

	$ret = 0;
	try{
		// Convert the XPS document to PDF
		echo(nl2br("Converting from XPS\n"));
		Convert::FromXps($pdfdoc, $s1 );
		$outputFile = "xps2pdf v2.pdf";
		$pdfdoc->Save($outputPath.$outputFile, SDFDoc::e_remove_unused);
		echo(nl2br("Saved ".$outputFile."\n"));


		// Convert the TXT document to PDF
		$set = new ObjSet();
		$options = $set->CreateDict();
		// Put options
		$options->PutNumber("FontSize", 15);
		$options->PutBool("UseSourceCodeFormatting", true);
		$options->PutNumber("PageWidth", 12);
		$options->PutNumber("PageHeight", 6);
		$s1 = $inputPath . "simple-text.txt";
		echo(nl2br("Converting from txt\n"));
		Convert::FromText($pdfdoc, $s1);
		$outputFile = "simple-text.pdf";
		$pdfdoc->Save($outputPath.$outputFile, SDFDoc::e_remove_unused);
		echo(nl2br("Saved ".$outputFile ."\n"));
		
		// Convert the two page PDF document to SVG
		$pdfdoc = new PDFDoc($inputPath . "newsletter.pdf");
		echo(nl2br("Converting pdfdoc to SVG\n"));
		$outputFile = "pdf2svg v2.svg";
		Convert::ToSvg($pdfdoc, $outputPath.$outputFile);
		echo(nl2br("Saved ".$outputFile."\n"));



		// Convert the PNG image to XPS
		echo(nl2br("Converting PNG to XPS\n"));
		$outputFile = "butterfly.xps";
		Convert::ToXps($inputPath."butterfly.png", $outputPath.$outputFile);
		echo(nl2br("Saved ".$outputFile."\n"));

		// Convert PDF document to XPS
		echo(nl2br("Converting PDF to XPS\n"));
		$outputFile = "newsletter.xps";
		Convert::ToXps($inputPath."newsletter.pdf", $outputPath.$outputFile);
		echo(nl2br("Saved ".$outputFile."\n"));

		// Convert PDF document to HTML
		echo(nl2br("Converting PDF to HTML\n"));
		$outputFile = "newsletter";
		Convert::ToHtml($inputPath."newsletter.pdf", $outputPath.$outputFile);
		echo(nl2br("Saved newsletter as HTML\n"));

		// Convert PDF document to EPUB
		echo(nl2br("Converting PDF to EPUB\n"));
		$outputFile = "newsletter.epub";
		Convert::ToEpub($inputPath."newsletter.pdf", $outputPath.$outputFile);
		echo(nl2br("Saved ".$outputFile."\n"));

		echo(nl2br("Converting PDF to multipage TIFF\n"));
		$tiff_options = new TiffOutputOptions();
		$tiff_options->SetDPI(200);
		$tiff_options->SetDither(true);
		$tiff_options->SetMono(true);
		Convert::ToTiff($inputPath . "newsletter.pdf", $outputPath. "newsletter.tiff", $tiff_options);
		echo(nl2br("Saved newsletter.tiff\n"));

		// Convert SVG file to PDF
		echo(nl2br("Converting SVG to PDF\n"));
		$pdfdoc = new PDFDoc();
		Convert::FromSVG($pdfdoc, $inputPath . "tiger.svg");
		$pdfdoc->Save($outputPath . "svg2pdf.pdf", SDFDoc::e_remove_unused);
		echo(nl2br("Saved svg2pdf.pdf\n"));
	}
    catch(Exception $e){
        $ret = 1;
	}
    return $ret;
}

function ConvertToPdfFromFile()
{
	global $inputPath, $outputPath;

	$testfiles = array(
	array("simple-word_2007.docx","docx2pdf.pdf"),
	array("simple-powerpoint_2007.pptx","pptx2pdf.pdf"),
	array("simple-excel_2007.xlsx","xlsx2pdf.pdf"),
	array("simple-text.txt","txt2pdf.pdf"),
	array("butterfly.png", "png2pdf.pdf"),
	array("simple-xps.xps", "xps2pdf.pdf"),
    );
    $ret = 0;
    foreach ($testfiles as &$testfile) {
		try{
			$pdfdoc = new PDFDoc();
			$inputFile = $testfile[0];
			$outputFile = $testfile[1];
			Printer::SetMode(Printer::e_prefer_builtin_converter);
			Convert::ToPdf($pdfdoc, $inputPath.$inputFile);
			$pdfdoc->Save($outputPath.$outputFile, SDFDoc::e_linearized);
	        	$pdfdoc->Close();
			echo(nl2br("Converted file: ".$inputFile."\n"));
			echo(nl2br("to: ".$outputFile."\n"));
		}
		catch(Exception $e)
		{
			$ret = 1;
		}
    }
	return $ret;
}

function 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.
	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.
	
	// Demonstrate Convert::ToPdf and Convert::Printer
	$err = ConvertToPdfFromFile();
	if ($err)
		echo(nl2br("ConvertFile failed\n"));
	else
		echo(nl2br("ConvertFile succeeded\n"));
	
	// Demonstrate Convert::[FromEmf, FromXps, ToEmf, ToSVG, ToXPS]
	$err = ConvertSpecificFormats();
	if ($err)
		echo(nl2br("ConvertSpecificFormats failed\n"));
	else
		echo(nl2br("ConvertSpecificFormats succeeded\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 PDF, XPS, or SVG, or EMF. The sample also shows how to convert MS Office files 
# using our built in conversion.
#
# Certain file formats such as XPS, EMF, PDF, and raster image formats can be directly 
# converted to PDF or XPS. 
#
# Please contact us if you have any questions.    
#---------------------------------------------------------------------------------------

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



def ConvertSpecificFormats():
    ret = 0
    try: 
        # Start with a PDFDoc to collect the converted documents
        pdfdoc = PDFDoc()
        s1 = inputPath + "simple-xps.xps"
        
        # Convert the XPS document to PDF
        print("Converting from XPS")
        Convert.FromXps(pdfdoc, s1)
        outputFile = "xps2pdf v2.pdf"
        pdfdoc.Save(outputPath + outputFile, SDFDoc.e_remove_unused)
        print("Saved " + outputFile)
        

        # Convert the TXT document to PDF
        set =  ObjSet()
        options = set.CreateDict()
        # Put options
        options.PutNumber("FontSize", 15)
        options.PutBool("UseSourceCodeFormatting", True)
        options.PutNumber("PageWidth", 12)
        options.PutNumber("PageHeight", 6)
        s1 = inputPath + "simple-text.txt"
        print("Converting from txt")
        Convert.FromText(pdfdoc, s1)
        outputFile = "simple-text.pdf"
        pdfdoc.Save(outputPath + outputFile, SDFDoc.e_remove_unused)
        print("Saved " + outputFile)
        
        # Convert the two page PDF document to SVG
        outputFile = "pdf2svg v2.svg"
        pdfdoc = PDFDoc(inputPath + "newsletter.pdf")
        print("Converting pdfdoc to SVG")
        Convert.ToSvg(pdfdoc, outputPath + outputFile)
        print("Saved " + outputFile)
        
        # Convert the PNG image to XPS
        print("Converting PNG to XPS")
        outputFile = "butterfly.xps"
        Convert.ToXps(inputPath + "butterfly.png", outputPath +outputFile)
        print("Saved " + outputFile)
            
        # Convert PDF document to XPS
        print("Converting PDF to XPS")
        outputFile = "newsletter.xps"
        Convert.ToXps(inputPath + "newsletter.pdf", outputPath + outputFile)
        print("Saved " + outputFile)
        
        # Convert PDF document to HTML
        print("Converting PDF to HTML")
        outputFile = "newsletter"
        Convert.ToHtml(inputPath + "newsletter.pdf", outputPath + outputFile)
        print("Saved newsletter as HTML")

        # Convert PDF document to EPUB
        print("Converting PDF to EPUB")
        outputFile = "newsletter.epub"
        Convert.ToEpub(inputPath + "newsletter.pdf", outputPath + outputFile)
        print("Saved " + outputFile)

        print("Converting PDF to multipage TIFF")
        tiff_options = TiffOutputOptions()
        tiff_options.SetDPI(200)
        tiff_options.SetDither(True)
        tiff_options.SetMono(True)
        Convert.ToTiff(inputPath + "newsletter.pdf", outputPath + "newsletter.tiff", tiff_options)
        print("Saved newsletter.tiff")

        # Convert SVG file to PDF
        print("Converting SVG to PDF")
        pdfdoc = PDFDoc()
        Convert.FromSVG(pdfdoc, inputPath + "tiger.svg")
        pdfdoc.Save(outputPath + "svg2pdf.pdf", SDFDoc.e_remove_unused)
        print("Saved svg2pdf.pdf")

    except:
        ret = 1
    return ret

# convert from a file to PDF automatically
def ConvertToPdfFromFile():
    testfiles = [
    [ "simple-word_2007.docx","docx2pdf.pdf"],
    [ "simple-powerpoint_2007.pptx","pptx2pdf.pdf"],
    [ "simple-excel_2007.xlsx","xlsx2pdf.pdf"],
    [ "simple-text.txt","txt2pdf.pdf"],
    [ "butterfly.png","png2pdf.pdf"],
    [ "simple-xps.xps","xps2pdf.pdf"],
    ]
    ret = 0


    for testfile in testfiles:
        try:
            pdfdoc = PDFDoc()
            inputFile = testfile[0]
            outputFile = testfile[1]
            Printer.SetMode(Printer.e_prefer_builtin_converter)

            Convert.ToPdf(pdfdoc, inputPath + inputFile)
            pdfdoc.Save(outputPath + outputFile, SDFDoc.e_linearized)
            pdfdoc.Close()
            print("Converted file: " + inputFile + "\nto: " + outputFile)
        except:
            ret = 1
            print("ERROR: on input file " + inputFile)
    return ret


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)
    
    # Demonstrate Convert.ToPdf and Convert.Printer
    err = ConvertToPdfFromFile()
    if err:
        print("ConvertFile failed")
    else:
        print("ConvertFile succeeded")

    # Demonstrate Convert.[FromEmf, FromXps, ToEmf, ToSVG, ToXPS]
    err = ConvertSpecificFormats()
    if err:
        print("ConvertSpecificFormats failed")
    else:
        print("ConvertSpecificFormats succeeded")


    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 PDF, XPS, or SVG, or EMF. The sample also shows how to convert MS Office files 
# using our built in conversion.
#
# Certain file formats such as XPS, EMF, PDF, and raster image formats can be directly 
# converted to PDF or XPS. 
#
# Please contact us if you have any questions.	
#
# Please contact us if you have any questions.    
#---------------------------------------------------------------------------------------

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


def ConvertSpecificFormats()
	ret = 0
	begin
		# Start with a PDFDoc to collect the converted documents
		pdfdoc = PDFDoc.new()
		s1 = $inputPath + "simple-xps.xps"
		
		puts "Converting from XPS"
		Convert.FromXps(pdfdoc, s1)
		outputFile = "xps2pdf v2.pdf"
		pdfdoc.Save($outputPath + outputFile, SDFDoc::E_remove_unused)
		puts "Saved " + outputFile

		# Convert the TXT document to PDF
		set =  ObjSet.new
		options = set.CreateDict()
		# Put options
		options.PutNumber("FontSize", 15)
		options.PutBool("UseSourceCodeFormatting", true)
		options.PutNumber("PageWidth", 12)
		options.PutNumber("PageHeight", 6)

		s1 = $inputPath + "simple-text.txt"
		puts "Converting from txt"
		Convert.FromText(pdfdoc, s1)
		outputFile = "simple-text.pdf"
		pdfdoc.Save($outputPath + outputFile, SDFDoc::E_remove_unused)
		puts("Saved " + outputFile)

		# Convert the two page PDF document to SVG
		outputFile = "pdf2svg v2.svg"
		pdfdoc = PDFDoc.new($inputPath + "newsletter.pdf")
		puts "Converting pdfdoc to SVG"
		Convert.ToSvg(pdfdoc, $outputPath + outputFile)
		puts "Saved " + outputFile
		
		# Convert the PNG image to XPS
		puts "Converting PNG to XPS"
		outputFile = "butterfly.xps"
		Convert.ToXps($inputPath + "butterfly.png", $outputPath + outputFile)
		puts "Saved " + outputFile
		
		# Convert PDF document to XPS
		puts "Converting PDF to XPS"
		outputFile = "newsletter.xps"
		Convert.ToXps($inputPath + "newsletter.pdf", $outputPath + outputFile)
		puts "Saved " + outputFile

		# Convert PDF document to HTML
		puts "Converting PDF to HTML"
		outputFile = "newsletter"
		Convert.ToHtml($inputPath + "newsletter.pdf", $outputPath + outputFile)
		puts "Saved newsletter as HTML"

		# Convert PDF document to EPUB
		puts "Converting PDF to EPUB"
		outputFile = "newsletter.epub"
		Convert.ToEpub($inputPath + "newsletter.pdf", $outputPath + outputFile)
		puts "Saved " + outputFile
		
		puts "Converting PDF to multipage TIFF"
		tiff_options = TiffOutputOptions.new
		tiff_options.SetDPI(200)
		tiff_options.SetDither(true)
		tiff_options.SetMono(true)
		Convert.ToTiff($inputPath + "newsletter.pdf", $outputPath + "newsletter.tiff", tiff_options)
		puts "Saved newsletter.tiff"

		pdfdoc = PDFDoc.new()
		puts "Converting SVG to PDF"
		Convert.FromSVG(pdfdoc, $inputPath + "tiger.svg")
		pdfdoc.Save($outputPath + "svg2pdf.pdf", SDFDoc::E_remove_unused)
		puts "Saved svg2pdf.pdf"
	rescue
		ret = 1
	end
	return ret
end

# convert from a file to PDF automatically
def ConvertToPdfFromFile()
	testfiles = [
		["simple-word_2007.docx","docx2pdf.pdf"],
		["simple-powerpoint_2007.pptx","pptx2pdf.pdf"],
		["simple-excel_2007.xlsx","xlsx2pdf.pdf"],
		["simple-text.txt","txt2pdf.pdf"],
		["butterfly.png", "png2pdf.pdf"],
		["simple-xps.xps", "xps2pdf.pdf"]
	]
	

	
	ret = 0
	for testfile in testfiles
		begin
			pdfdoc = PDFDoc.new()
			inputFile = testfile[0]
			outputFile = testfile[1]
			Printer.SetMode(Printer::E_prefer_builtin_converter)
			Convert.ToPdf(pdfdoc,  $inputPath + inputFile)
			pdfdoc.Save($outputPath + outputFile, SDFDoc::E_compatibility)
			pdfdoc.Close()
			puts "Converted file: " + inputFile + "\nto: " + outputFile
		rescue
			ret = 1
		end
	end
	
	return ret
end

	
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)
	
	# Demonstrate Convert.ToPdf and Convert.Printer
	err = ConvertToPdfFromFile()
	if err == 1
		puts "ConvertFile failed"
	else
		puts "ConvertFile succeeded"
	end
	# Demonstrate Convert.[FromEmf, FromXps, ToEmf, ToSVG, ToXPS]
	err = ConvertSpecificFormats()
	if err == 1
		puts "ConvertSpecificFormats failed"
	else
		puts "ConvertSpecificFormats succeeded"
	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 System.Drawing
Imports System.Drawing.Drawing2D
Imports pdftron
Imports pdftron.Common
Imports pdftron.Filters
Imports pdftron.SDF
Imports pdftron.PDF

' The following sample illustrates how to use the PDF::Convert utility class to convert 
' documents and files to PDF, XPS, or SVG, or EMF. The sample also shows how to convert MS Office files 
' using our built in conversion.
' 
' Certain file formats such as XPS, EMF, PDF, and raster image formats can be directly 
' converted to PDF or XPS. 
' 
' 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 ConvertTestVB
    Class Testfile
        Public inputFile, outputFile As String

        Public Sub New(ByVal inFile As String, ByVal outFile As String)
            inputFile = inFile
            outputFile = outFile
        End Sub
    End Class

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

        Shared Sub New()
        End Sub

        Const inputPath As String = "../../../../TestFiles/"
        Const outputPath As String = "../../../../TestFiles/Output/"

        Private Shared Function ConvertSpecificFormats() As Boolean
            Dim err As Boolean = False

            Try

                Using pdfdoc As PDFDoc = New PDFDoc()
                    Console.WriteLine("Converting from XPS")
                    pdftron.PDF.Convert.FromXps(pdfdoc, inputPath & "simple-xps.xps")
                    pdfdoc.Save(outputPath & "xps2pdf v2.pdf", SDFDoc.SaveOptions.e_remove_unused)
                    Console.WriteLine("Saved xps2pdf v2.pdf")
                End Using

            Catch e As PDFNetException
                Console.WriteLine(e.Message)
                err = True
            End Try

            Try
                Using pdfdoc As PDFDoc = New PDFDoc()
                    Dim [set] As ObjSet = New ObjSet()
                    Dim options As Obj = [set].CreateDict()
                    options.PutNumber("FontSize", 15)
                    options.PutBool("UseSourceCodeFormatting", True)
                    options.PutNumber("PageWidth", 12)
                    options.PutNumber("PageHeight", 6)
                    Console.WriteLine("Converting from txt")
                    pdftron.PDF.Convert.FromText(pdfdoc, inputPath & "simple-text.txt", options)
                    pdfdoc.Save(outputPath & "simple-text.pdf", SDFDoc.SaveOptions.e_remove_unused)
                    Console.WriteLine("Saved simple-text.pdf")
                End Using

            Catch e As PDFNetException
                Console.WriteLine(e.Message)
                err = True
            End Try

            Try

                Using pdfdoc As PDFDoc = New PDFDoc(inputPath & "newsletter.pdf")
                    Console.WriteLine("Converting pdfdoc to SVG")
                    pdftron.PDF.Convert.ToSvg(pdfdoc, outputPath & "pdf2svg v2.svg")
                    Console.WriteLine("Saved pdf2svg v2.svg")
                End Using

            Catch e As PDFNetException
                Console.WriteLine(e.Message)
                err = True
            End Try

            Try
                Console.WriteLine("Converting PNG to XPS")
                pdftron.PDF.Convert.ToXps(inputPath & "butterfly.png", outputPath & "butterfly.xps")
                Console.WriteLine("Saved butterfly.xps")
            Catch e As PDFNetException
                Console.WriteLine(e.Message)
                err = True
            End Try

            Try
                Console.WriteLine("Converting PDF to XPS")
                pdftron.PDF.Convert.ToXps(inputPath & "newsletter.pdf", outputPath & "newsletter.xps")
                Console.WriteLine("Saved newsletter.xps")
            Catch e As PDFNetException
                Console.WriteLine(e.Message)
                err = True
            End Try

            Try
                Console.WriteLine("Converting PDF to HTML")
                pdftron.PDF.Convert.ToHtml(inputPath & "newsletter.pdf", outputPath & "newsletter")
                Console.WriteLine("Saved newsletter as HTML")
            Catch e As PDFNetException
                Console.WriteLine(e.Message)
                err = True
            End Try

            Try
                Console.WriteLine("Converting PDF to EPUB")
                pdftron.PDF.Convert.ToEpub(inputPath & "newsletter.pdf", outputPath & "newsletter.epub")
                Console.WriteLine("Saved newsletter.epub")
            Catch e As PDFNetException
                Console.WriteLine(e.Message)
                err = True
            End Try

            Try
                Console.WriteLine("Converting PDF to multipage TIFF")
                Dim tiff_options As pdftron.PDF.Convert.TiffOutputOptions = New pdftron.PDF.Convert.TiffOutputOptions()
                tiff_options.SetDPI(200)
                tiff_options.SetDither(True)
                tiff_options.SetMono(True)
                pdftron.PDF.Convert.ToTiff(inputPath & "newsletter.pdf", outputPath & "newsletter.tiff", tiff_options)
                Console.WriteLine("Saved newsletter.tiff")
            Catch e As PDFNetException
                Console.WriteLine(e.Message)
                err = True
            End Try

            Try

                Using pdfdoc As PDFDoc = New PDFDoc()
                    Console.WriteLine("Converting SVG to PDF")

                    pdftron.PDF.Convert.FromSvg(pdfdoc, inputPath & "tiger.svg", Nothing)
                    pdfdoc.Save(outputPath & "svg2pdf.pdf", SDFDoc.SaveOptions.e_remove_unused)

                    Console.WriteLine("Saved svg2pdf.pdf")
                End Using

            Catch e As PDFNetException
                Console.WriteLine(e.Message)
                err = True
            End Try

            Return err
        End Function

        Private Shared Function ConvertToPdfFromFile() As Boolean
            Dim testfiles As System.Collections.ArrayList = New System.Collections.ArrayList()
            testfiles.Add(New ConvertTestVB.Testfile("simple-powerpoint_2007.pptx", "pptx2pdf.pdf"))
            testfiles.Add(New ConvertTestVB.Testfile("simple-text.txt", "txt2pdf.pdf"))
            testfiles.Add(New ConvertTestVB.Testfile("simple-word_2007.docx", "docx2pdf.pdf"))
            testfiles.Add(New ConvertTestVB.Testfile("simple-excel_2007.xlsx", "xlsx2pdf.pdf"))
            testfiles.Add(New ConvertTestVB.Testfile("butterfly.png", "png2pdf.pdf"))
            testfiles.Add(New ConvertTestVB.Testfile("simple-xps.xps", "xps2pdf.pdf"))

            Dim err As Boolean = False

            For Each file As Testfile In testfiles
                Try

                    Using pdfdoc As pdftron.PDF.PDFDoc = New PDFDoc()

                        pdftron.PDF.Convert.Printer.SetMode(PDF.Convert.Printer.Mode.e_prefer_builtin_converter)
                        pdftron.PDF.Convert.ToPdf(pdfdoc, inputPath & file.inputFile)
                        pdfdoc.Save(outputPath & file.outputFile, SDFDoc.SaveOptions.e_linearized)
                        Console.WriteLine("Converted file: " & file.inputFile)
                        Console.WriteLine("to: " & file.outputFile)
                    End Using

                Catch e As PDFNetException
                    Console.WriteLine("ERROR: on input file " & file.inputFile)
                    Console.WriteLine(e.Message)
                    err = True
                End Try
            Next

            Return err
        End Function

        <STAThread>
        Shared Sub Main(ByVal args As String())
            PDFNet.Initialize(PDFTronLicense.Key)
            Dim err As Boolean = False
            err = ConvertToPdfFromFile()

            If err Then
                Console.WriteLine("ConvertFile failed")
            Else
                Console.WriteLine("ConvertFile succeeded")
            End If

            err = ConvertSpecificFormats()

            If err Then
                Console.WriteLine("ConvertSpecificFormats failed")
            Else
                Console.WriteLine("ConvertSpecificFormats succeeded")
            End If

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