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#
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.FixedDocumentSequenceReaderDim 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.XmlReaderIf 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 WhileEnd IfDim allText As String = curText.ToString
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}
Open in new window