Some test text!


VB PDF converter (SVG, XPS, TIFF, JPG, RTF, TXT, more)

More languages

More languages
Java (Android)
C# (.NET Core)
JS (Node.js)
C# (UWP)

Sample VB code to use PDFTron SDK 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 printable document (ex. TXT, RTF, Word, HTML, MS Office, DXF, DWG, etc) to PDF or XPS using a universal document converter. Learn more about our VB PDF Library and PDF Conversion Library.

Get StartedSamplesDownload

To run this sample, get started with a free trial of PDFTron SDK.

' Copyright (c) 2001-2020 by PDFTron Systems Inc. All Rights Reserved.

Imports System

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, 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, or .NET Framework
' 3.x or higher. For older versions of .NET Framework running on Windows XP or Vista SP0 you need to install 
' the XPS Essentials Pack (or equivalent redistributables). 
' Also note that conversion under ASP.NET can be tricky to configure. Please see the following document for advice: 
Module ConvertTestVB
    Dim pdfNetLoader As PDFNetLoader
    Sub New()
        pdfNetLoader = pdftron.PDFNetLoader.Instance()
    End Sub

    ' Relative path to the folder containing test files.
    Dim input_path As String = "../../../../TestFiles/"
    Dim output_path As String = "../../../../TestFiles/Output/"

    Sub Main()




            ' Start with a PDFDoc to add other files to 
            Using pdf_doc As PDFDoc = New PDFDoc
                Console.WriteLine("Converting xps and emf files to PDF")
                pdftron.PDF.Convert.FromXps(pdf_doc, input_path + "simple-xps.xps")
                pdftron.PDF.Convert.FromEmf(pdf_doc, input_path + "simple-emf.emf")

                pdf_doc.Save(output_path + "ConvertTest.pdf", SDF.SDFDoc.SaveOptions.e_linearized)
                Console.WriteLine("Wrote " + output_path + "ConvertTest.pdf")

                ' Convert the PDF document to XPS
                Console.WriteLine("Converting PDFDoc to XPS file")
                pdftron.PDF.Convert.ToXps(pdf_doc, output_path + "ConvertTest2.xps")
            End Using
            Console.WriteLine("Wrote " + output_path + "ConvertTest2.xps")

            Using pdf_doc As PDFDoc = New PDFDoc
                Console.WriteLine("Converting plain text file to PDF")
                Dim objset As SDF.ObjSet = New SDF.ObjSet
                Dim Options As SDF.Obj = objset.CreateDict()
                Options.PutNumber("PageWidth", 12)
                Options.PutNumber("FontSize", 25)
                Options.PutNumber("PageHeight", 4)
                pdftron.PDF.Convert.FromText(pdf_doc, input_path + "simple-text.txt", Options)
                pdf_doc.Save(output_path + "simple-text.pdf", SDF.SDFDoc.SaveOptions.e_linearized)
            End Using

            If pdftron.PDF.Convert.Printer.IsInstalled("PDFTron Creator") Then
                pdftron.PDF.Convert.Printer.SetPrinterName("PDFTron Creator")
            ElseIf Not pdftron.PDF.Convert.Printer.IsInstalled() Then
                Console.WriteLine("Installing printer (requires administrator)")
                Console.WriteLine("Installed printer " + pdftron.PDF.Convert.Printer.GetPrinterName())
            End If

			Console.WriteLine("Converting MSWord docx to pdf file")

			Using pdf_doc As PDFDoc = New PDFDoc
				pdftron.PDF.Convert.ToPdf(pdf_doc, input_path + "simple-word_2007.docx")
				pdf_doc.Save(output_path + "ConvertTest_3.pdf", SDF.SDFDoc.SaveOptions.e_linearized)
			End Using
			Console.WriteLine("Wrote " + output_path + "ConvertTest_3.pdf")

			Console.WriteLine("Converting MSWord docx to xps file")
			pdftron.PDF.Convert.ToXps(input_path + "simple-word_2007.docx", output_path + "ConvertTest4.xps")
			Console.WriteLine("Wrote " + output_path + "ConvertTest4.pdf")

			Console.WriteLine("Uninstalling printer (requires administrator)")
			Console.WriteLine("Uninstalled printer " + pdftron.PDF.Convert.Printer.GetPrinterName())

			Console.WriteLine("Converting PNG file to XPS file")
			pdftron.PDF.Convert.ToXps(input_path + "butterfly.png", output_path + "ConvertTest5.xps")
			Console.WriteLine("Wrote " + output_path + "ConvertTest5.pdf")

			Console.WriteLine("Converting PDF file to XPS file")
			pdftron.PDF.Convert.ToXps(input_path + "newsletter.pdf", output_path + "ConvertTest6.xps")
			Console.WriteLine("Wrote " + output_path + "ConvertTest6.pdf")

			Console.WriteLine("Converting PDF file to HTML")
			pdftron.PDF.Convert.ToHtml(input_path + "newsletter.pdf", output_path + "newsletter")
			Console.WriteLine("Wrote " + output_path + "newsletter")

			Console.WriteLine("Converting PDF file to EPUB")
			pdftron.PDF.Convert.ToEpub(input_path + "newsletter.pdf", output_path + "newsletter.epub")
			Console.WriteLine("Wrote " + output_path + "newsletter.epub")

			Console.WriteLine("Converting PDF file to multipage TIFF")
			pdftron.PDF.Convert.ToTiff(input_path + "newsletter.pdf", output_path + "newsletter.tiff")
			Console.WriteLine("Wrote " + output_path + "newsletter.tiff")


		Catch ex As PDFNetException


		Catch ex As Exception


		End Try

	End Sub

End Module

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

Join our live demo to learn about use cases & capabilities for WebViewer

Learn more