Avatar of Natavia Finnie
Natavia Finnie
Flag for United States of America asked on

Reading lines in .xps file programmatically using vb.net

I am using VB.NET and I am trying to read each line from an .xps file.  I have found the code to access the file and display it using the by importing System.Windows.Xps.Packaging.  I now need help to read the file and access the tables in the file and I also need to know if certain text is bold and red.

Please help....
.NET ProgrammingVisual Basic.NETC#

Avatar of undefined
Last Comment
darbid73

8/22/2022 - Mon
darbid73

With respect to just reading your text this is one possible way.

Dim xpsDoc As New XpsDocument("/pathToYourFile", System.IO.FileAccess.Read)
Dim fixedDocSeqReader As IXpsFixedDocumentSequenceReader = xpsDoc.FixedDocumentSequenceReader
Dim doc As IXpsFixedDocumentReader = fixedDocSeqReader.FixedDocuments(0)
Dim page As IXpsFixedPageReader = doc.FixedPages(documentViewerElement.MasterPageNumber)
Dim curText As New StringBuilder()

Dim pgReader As System.Xml.XmlReader = page.XmlReader

If pgReader IsNot Nothing Then
	While pgReader.Read()
		If pgReader.Name = "Glyphs" Then
			If pgReader.HasAttributes Then
				If pgReader.GetAttribute("UnicodeString") IsNot Nothing Then
					_currentText.Append(pgReader.GetAttribute("UnicodeString"))
				End If
			End If
		End If
	End While
End If

Dim allText As String = curText.ToString

Open in new window

Natavia Finnie

ASKER
Dim page As IXpsFixedPageReader = doc.FixedPages(documentViewerElement.MasterPageNumber) gives me an error say 'documentViewerElement' is not declared. It may be inaccessible due to protection level.

When i put Dim page As IXpsFixedPageReader = doc.FixedPages(0) then page returns {None}
ASKER CERTIFIED SOLUTION
darbid73

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61