Some test text!

< Windows samples

ConvertTest - VB

This sample shows how to use PDFNet Convert Add-on (i.e. 'pdftron.PDF.Convert' namespace) for direct, high-quality conversion between PDF, XPS, EMF, SVG, TIFF, PNG, JPEG, and other image formats. The sample also shows how to convert any printable document (e.g. Word, HTML, RTF, MS Office, DXF, DWG, etc) to PDF or XPS using a universal document converter.

'
' Copyright (c) 2001-2018 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: 
' http://www.pdftron.com/pdfnet/faq_files/Converting_Documents_in_Windows_Service_or_ASP.NET_Application_using_PDFNet.pdf
Module ConvertTestVB
    Dim pdfNetLoader As PDFNetLoader = pdftron.PDFNetLoader.Instance()

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

    Sub Main()

        PDFNet.Initialize()

        Try

            Console.WriteLine("-------------------------------------------------")

            ' 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)")
                pdftron.PDF.Convert.Printer.Install()
                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)")
			pdftron.PDF.Convert.Printer.Uninstall()
			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")

			Console.WriteLine("Done.")

		Catch ex As PDFNetException

			Console.WriteLine(ex.Message)

		Catch ex As Exception

			MsgBox(ex.Message)

		End Try

	End Sub

End Module