Some test text!

Loading...
Guides

Convert PDF to Word in VB

More languages

More languages
C++
C#
C# (.NET Core)
Go
Java
JS (Node.js)
PHP
Python
Ruby
VB

Sample VB code for using PDFTron SDK to programmatically convert generic PDF documents to HTML. Learn more about our VB PDF to Word

Get Started Samples Download

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

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

Imports System
Imports pdftron
Imports pdftron.Common
Imports pdftron.PDF

' The following sample illustrates how to use the PDF:Convert utility Class To convert 
' documents And files to Word.
'
' The Word module Is an optional PDFNet Add-on that can be used to convert PDF
' documents into Word documents.
'
' The PDFTron SDK Word module can be downloaded from http://www.pdftron.com/
'
' Please contact us if you have any questions.	
'
' 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 PDF2WordTestVB
    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/"

        <STAThread>
        Shared Sub Main(ByVal args As String())
            ' 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)

            PDFNet.AddResourceSearchPath("../../../../../Lib/")

            If Not PDF2WordModule.IsModuleAvailable() Then
                Console.WriteLine()
                Console.WriteLine("Unable to run the sample: PDFTron SDK Word module not available.")
                Console.WriteLine("---------------------------------------------------------------")
                Console.WriteLine("The Word module is an optional add-on, available for download")
                Console.WriteLine("at http://www.pdftron.com/. If you have already downloaded this")
                Console.WriteLine("module, ensure that the SDK is able to find the required files")
                Console.WriteLine("using the PDFNet::AddResourceSearchPath() function.")
                Console.WriteLine()
                Return
            End If

            Dim err As Boolean = False

            '//////////////////////////////////////////////////////////////////////////

            Try
                ' Convert PDF document to Word
                Console.WriteLine("Converting PDF to Word")

                Dim outputFile As String = outputPath & "paragraphs_and_tables.docx"

                pdftron.PDF.Convert.ToWord(inputPath & "paragraphs_and_tables.pdf", outputFile)

                Console.WriteLine("Result saved in " & outputFile)
            Catch e As PDFNetException
                Console.WriteLine("Unable to convert PDF document to Word, error: " & e.Message)
                err = True
            Catch e As Exception
                Console.WriteLine("Unknown Exception, error: ")
                Console.WriteLine(e)
                err = True
            End Try

            '//////////////////////////////////////////////////////////////////////////

            Try
                ' Convert PDF document to Word with options
                Console.WriteLine("Converting PDF to Word with options")

                Dim outputFile As String = outputPath & "paragraphs_and_tables_first_page.docx"

                Dim wordOutputOptions As pdftron.PDF.Convert.WordOutputOptions = New pdftron.PDF.Convert.WordOutputOptions()

                ' Convert only the first page
                wordOutputOptions.SetPages(1, 1)

                pdftron.PDF.Convert.ToWord(inputPath & "paragraphs_and_tables.pdf", outputFile, wordOutputOptions)

                Console.WriteLine("Result saved in " & outputFile)
            Catch e As PDFNetException
                Console.WriteLine("Unable to convert PDF document to Word, error: " & e.Message)
                err = True
            Catch e As Exception
                Console.WriteLine("Unknown Exception, error: ")
                Console.WriteLine(e)
                err = True
            End Try

            '//////////////////////////////////////////////////////////////////////////

            PDFNet.Terminate()
            Console.WriteLine("Done.")
        End Sub
    End Class
End Module