Generated XPS file has an invalid NavigateUri attribute


#1

  • open the attached msg file inside an aspose MailMessage object
  • save the contents to a MemoryStream in mhtml format
  • use the MemoryStream to construct an aspose Words.Document
  • save the Words.Document as an xps file
  • open the xps file inside a .NET XpsDocument object
  • call xpsDoc.GetFixedDocumentSequence and it will raises two successive exceptions

System.UriFormatException occurred
  Message=Invalid URI: The hostname could not be parsed.
  Source=System
  StackTrace:
       at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
  InnerException: 
System.Windows.Markup.XamlParseException occurred
  Message=Cannot convert string 'http://www.kutana.co.uk%3chttp:/www.kutana.co.uk/' in attribute 'NavigateUri' to object of type 'System.Uri'. Invalid URI: The hostname could not be parsed.  Error at object 'System.Windows.Documents.Glyphs', Line 46 Position 885.
  Source=PresentationFramework
  LineNumber=46
  LinePosition=885
  NameContext=Page1
  StackTrace:
       at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
  InnerException: System.UriFormatException
       Message=Invalid URI: The hostname could not be parsed.
       Source=System
       StackTrace:
            at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
            at System.UriTypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
            at System.Windows.Markup.XamlTypeMapper.ParseProperty(Object targetObject, Type propType, String propName, Object dpOrPiOrFi, ITypeDescriptorContext typeContext, ParserContext parserContext, String value, Int16 converterTypeId)
       InnerException:
The exception occurs because the NavigateUri attribute in the generated xps file is malformed:
<Glyphs OriginX="26.468999863" OriginY="10.473999977" 
  UnicodeString="www.kutana.co.uk<http://www.kutana.co.uk/" 
  Indices="449,71.484375;449,71.484375;449,71.484375;856,25.244140625;364,45.458984375;437,52.5390625;410,33.49609375;258,47.900390625;374,52.5390625;258,47.900390625;856,25.244140625;272,42.28515625;381,52.734375;856,25.244140625;437,52.5390625;364,45.458984375;1092,49.8046875;346,52.5390625;410,33.49609375;410,33.49609375;393,52.5390625;855,26.7578125;876,38.623046875;876,38.623046875;449,71.484375;449,71.484375;449,71.484375;856,25.244140625;364,45.458984375;437,52.5390625;410,33.49609375;258,47.900390625;374,52.5390625;258,47.900390625;856,25.244140625;272,42.28515625;381,52.734375;856,25.244140625;437,52.5390625;364,45.458984375;876,38.623046875" 
  Fill="#FF0563C1" 
  FontRenderingEmSize="11" 
  FontUri="/Resources/99c2763d-ae70-4a4a-8857-910e33c80ed8.odttf" 
  FixedPage.NavigateUri="http://www.kutana.co.uk%3chttp:/www.kutana.co.uk/" />

This exception halts my app. There are a couple of places where I could deal with the problem:

  1. I know that this particular initial msg has malformed content. Could I fix the contents of the MailMessage object?
  2. The generated mhtml and xps content each have a malformed Uri. Can I set options so the generated Mhtml or xps has a legitimate NavigateUri value instead?
  3. Is there an option to the XpsDocument so it doesn't try to parse the NavigateUri attribute?

I don't need the Uri to be validated as I'm printing the xps content, not presenting it via a UI allowing a user to click and follow the link.


#2

Hi Brian,

You can use the following code to update the hyperlinks in the MHT document before saving to XPS. Please let us know if this fixes the issue at your end.

var document = new Aspose.Words.Document(mhtStream, loadOptions);

foreach (Aspose.Words.Fields.Field field in document.Range.Fields)

{

if (field.Type == Aspose.Words.Fields.FieldType.FieldHyperlink)

{

Aspose.Words.Fields.FieldHyperlink hyperlink = (Aspose.Words.Fields.FieldHyperlink)field;

<?xml:namespace prefix = "o" ns = "urn:schemas-microsoft-com:office:office" />

// Some hyperlinks can be local (links to bookmarks inside the document), ignore these.

if (hyperlink.SubAddress != null)

continue;

hyperlink.Address = "";

hyperlink.Result = "";

}

}

Best Regards,


#3

Very many thanks Muhammad. I used the code exactly as supplied, except that I commented out the line that assigns the empty string to Result, because I wanted the text of the link still to be visible on my printout. But setting the Address to the empty string as you suggested meant that the generated xps had the NavigateUri attribute set to the empty string, which is exactly what I wanted.

<Glyphs 
  OriginX="26.468999863" 
  OriginY="10.473999977" 
  UnicodeString="www.kutana.co.uk<http://www.kutana.co.uk/" 
  Indices="449,71.484375;449,71.484375;449,71.484375;856,25.244140625;364,45.458984375;437,52.5390625;410,33.49609375;258,47.900390625;374,52.5390625;258,47.900390625;856,25.244140625;272,42.28515625;381,52.734375;856,25.244140625;437,52.5390625;364,45.458984375;1092,49.8046875;346,52.5390625;410,33.49609375;410,33.49609375;393,52.5390625;855,26.7578125;876,38.623046875;876,38.623046875;449,71.484375;449,71.484375;449,71.484375;856,25.244140625;364,45.458984375;437,52.5390625;410,33.49609375;258,47.900390625;374,52.5390625;258,47.900390625;856,25.244140625;272,42.28515625;381,52.734375;856,25.244140625;437,52.5390625;364,45.458984375;876,38.623046875" 
  Fill="#FF0563C1" 
  FontRenderingEmSize="11" 
  FontUri="/Resources/e0dd8932-9da5-4e11-8011-0eeef61f199e.odttf" 
  FixedPage.NavigateUri="" />

#4

Hi Brian,

Good to know that the issue has been resolved and thanks for letting us know.

Best Regards,


#5

I originally reported this behaviour converting MSG to DOCX to XPS.

You supplied a workaround for this issue.

But now I'm seeing a similar issue printing a particular PDF file to XPS. I get problems due to the NavigateUri in the generated XPS.

Can you tell me what aspose flags I need to use so that when I save to XPS from PDF the XPS has a blank or non-existent NavigateUri attribute?


#6

Hi Brian,


Thanks for your inquriy. I am afraid currently we do not have any additional settings for PDF to XPS conversion. However we will appreciate it if you please share your problematic PDF document here, so we will look into it and will provide information accordingly.

We are sorry for the inconvenience.

Best Regards,

#7

Hi guys,

We are having a weird issue when trying to load the XPS document using PDF document object using Java library and we are not able to detect the links in the FixedPath.NavigateUri attribute from the tags on the XPS document page.

Do you know how can we get those fields?

Thanks & Regards,
Mimecast


#8

@mimecast

Thanks for contacting support.

Would you please share your sample XPS document with us along with sample code snippet. We will test the scenario in our environment and address it accordingly.