How to Edit or replace the text or the hyperlinks of XPS File using System.Windows.XPS.Packaging?

Akbar Husain 0 Reputation points
2023-03-24T09:21:21.3033333+00:00

Hello,

  1. Here I am trying to Update or edit the existing Text or Hyperlinks from XPS File. So I have seen a way using System.Windows.XPS.Packaging. By using this I have successfully read the content of the file but unable to write in it.

So kindly please suggest me further.

For you reference I am attaching the sample code below and the sample file.

I am not able to attached the xps or zip file so please take one sample file.

  1. There is any "XpsDetails" class in System.Windows.Xps.Packaging?

Code:

XpsDocument _xpsDocument=new XpsDocument("/path",System.IO.FileAccess.Read);
IXpsFixedDocumentSequenceReader fixedDocSeqReader 
    =_xpsDocument.FixedDocumentSequenceReader;
IXpsFixedDocumentReader _document = fixedDocSeqReader.FixedDocuments[0];
IXpsFixedPageReader _page 
    = _document.FixedPages[documentViewerElement.MasterPageNumber];
StringBuilder _currentText = new StringBuilder();
System.Xml.XmlReader _pageContentReader = _page.XmlReader;
if (_pageContentReader != null)
{
  while (_pageContentReader.Read())
  {
    if (_pageContentReader.Name == "Glyphs")
    {
      if (_pageContentReader.HasAttributes)
      {
        if (_pageContentReader.GetAttribute("UnicodeString") != null )
        {                                   
          _currentText.
            Append(_pageContentReader.
            GetAttribute("UnicodeString"));                              
        }
      }
    }
  }
}
string _fullPageText = _currentText.ToString();
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,671 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,604 questions
Microsoft System Center
Microsoft System Center
A suite of Microsoft systems management products that offer solutions for managing datacenter resources, private clouds, and client devices.
824 questions
{count} votes