Some test text!

< Windows samples

ElementReaderTest - VB

Illustrates how to traverse page display list using ElementReader.

'
' 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

Module ElementReaderTestVB
    Dim pdfNetLoader As PDFNetLoader = pdftron.PDFNetLoader.Instance()

    Sub ProcessElements(ByVal reader As ElementReader)
        Dim element As Element = reader.Next()
        While Not IsNothing(element)  ' Read page contents
            If element.GetType() = element.Type.e_path Then
                ' Process path data...
                Dim pathData As PathData = element.GetPathData()
                Dim data As Double() = pathData.points
                Console.WriteLine("Process Element.Type.e_path")
            ElseIf element.GetType() = element.Type.e_text Then
                ' Process text strings...
                Dim sz As Integer = element.GetTextDataSize()
                Dim data As String = element.GetTextString()
                Console.WriteLine("Process Element.Type.e_text")
                ' Console.WriteLine(data)
            ElseIf element.GetType() = element.Type.e_image Then
                ' Process images...
                Console.WriteLine("Process Element.Type.e_image")
            ElseIf element.GetType() = element.Type.e_form Then
                ' Process form XObjects
                reader.FormBegin()
                Console.WriteLine("Process Element.Type.e_form")
                ProcessElements(reader)
                reader.End()
            End If
            element = reader.Next()
        End While
    End Sub

    Sub Main()

        PDFNet.Initialize()

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

        Console.WriteLine("-------------------------------------------------")
        Console.WriteLine("Extract text data from all pages in the document.")

        ' Open the test file
        Console.WriteLine("Opening the input file...")
		Using doc As PDFDoc = New PDFDoc(input_path + "newsletter.pdf")
			doc.InitSecurityHandler()

			Dim itr As PageIterator = doc.GetPageIterator()

			Using page_reader As ElementReader = New ElementReader
				While itr.HasNext()	 '  Read every page
					Console.WriteLine("Page {0:d} ----------------------------------------", _
						itr.GetPageNumber())

					page_reader.Begin(itr.Current())
					ProcessElements(page_reader)
					page_reader.End()
					itr.Next()
				End While
			End Using
		End Using
		Console.WriteLine("Done.")

    End Sub

End Module