none
Excel exports to XPS creating <t>_x000D_ that crashes xpsDoc.GetFixedDocumentSequence

    Question

  • Excel exports to XPS creating <t>_x000D_   that crashes xpsDoc.GetFixedDocumentSequence

    Asked the same question on Excel forum, and advised to post it here:

    I have an issue with XPS file created by Excel export\CreateXPS from all Excel versions (2007, 2010, 2013), and regardless if convert\SaveAsXPS is done from xls, or from resaved XLSX file.

    When this XPS file is viewed by .NET WPF code xpsDoc.GetFixedDocumentSequence such:

    string xpsDocName=GetXPSDocFullPath(“ 5773recordbad1.xps”);

    XpsDocument xpsDoc = new XpsDocument(xpsDocName, System.IO.FileAccess.Read);

    documentViewer1.Document = xpsDoc.GetFixedDocumentSequence();

    Or the following code  on GetPage(pagenumber) of DocumentPaginator class as:

    mPaginator = mFixedDocumentSequence->DocumentPaginator;
    page = mPaginator->GetPage(pagenumber);

    It throws the exception:

    An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

    Additional information: 'Initialization of 'System.Windows.Documents.FixedDocument' threw an exception.' Line number…

    +_innerException       {"UnicodeString property does not contain enough characters to correspond to the contents of Indices property."}     System.Exception {System.ArgumentException}

    TargetSite       {Int32 ParseGlyphsProperty(System.Windows.Media.GlyphTypeface, System.String, Boolean, System.Collections.Generic.List`1[System.Windows.Documents.Glyphs+ParsedGlyphData] ByRef, UInt16[] ByRef)}       System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}

    The sample code here does no changes to Excel created XPS file,  calls only WPF XPSDocument and FixedDocument  classes, no explicit calls to  XAML parser.

    So I assume the issue is  either in Excel SaveAsXPS(not to make a text object that causes this issue), or  WPF fixed document, fixed page  DocumentPaginator level,  not to throw this exception, but need to confirm that.

    XLS file to start with, is our customer  file,  and we are asked to fix the issue since XPS Viewer is viewing the XPS file created by Excel from this  customer XLS file.

     I have isolated one cell text from this customer file, that causes the exception issue when converted from XLS/XLSX to XPS, and it has hex 000D  at the beginning of Text/Glyphs run, which crashes fixeddocument pagination.

    Here is this cell text from xlsx  ..\xl\sharedStrings.xml content:

    ?xml version="1.0" encoding="UTF-8" standalone="yes"?>

    <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="3" uniqueCount="3"><si><t>_x000D_G1-VE-E-8300-B01E44010116</t></si><si><t>7.0/23.0</t></si><si><t>G1-VE-E-8300-B01E44010116.PDF</t></si></sst>

    And converted to XPS Documents\1\Pages\1.fpage as:

    <FixedPage xmlns="http://schemas.microsoft.com/xps/2005/06" Width="816"

    Height="1056" xml:lang="en-US">

     <Canvas>

      <Canvas.RenderTransform>

       <MatrixTransform Matrix="1.333333333,0,0,1.333333333,0,0"/>

      </Canvas>

      <Canvas Clip="M 101.78,54.96 L 217.37,54.96 L 217.37,68.52 L 101.78,68.52 Z ">

       <Glyphs Name="a1" BidiLevel="0" Fill="#FF0000FF"

       FontUri="/Resources/62D230AD-6051-34FB-B774-C94C774DB004.odttf"   FontRenderingEmSize="7.8" StyleSimulations="None" OriginX="102.98"

       OriginY="65.76" UnicodeString="&#13; G1-VE-E-8300-B01E44010116"   Indices=",0;,0;,80;,56.923;,33.846;,69.231;,69.231;,33.846;,69.231;,33.846;,56.923;,56.923;,56.923;,56.923;,33.846;,69.231;,56.923;,56.923;,69.231;,56.923;,56.923;,56.923;,56.923;,56.923;,49.231;,56.923;"

       xml:lang="x-none">

       </Glyphs>

      </Canvas>

    … my guess:

    Perhaps  Unicode string in Glyphs run filters control characters "&#13” but  the indices are not filtered,  so the first 2 indices 0;,0;  are unmatched, and it throws the exception.

    Appreciated if anybody knows about this issue, and if so where/what the solution is?

    • Edited by gloryslave Tuesday, April 16, 2013 8:02 PM
    Tuesday, April 16, 2013 7:56 PM

All replies

  • hi,

    >>An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

    This is normally caused by not having all dependencies copied to the output. As you say the error message is not very helpful, but I would check that your application has all the necessary dependencies available to resolve the parsed types.

    Normally it is enough to set Copy Local to true for referenced assemblies, but I've experienced some cases where references themselves reference assemblies, so it can be necessary to explicitly add those references as well.

    Check-out this link please:http://stackoverflow.com/questions/4615597/xamlparseexception-after-deploying-wpf-project

    I am confused with these mess information you provided, maybe a sample application will help us to understand this problem. Can you upload a sample project to SkyDrive which can reproduce this issue?

    Tuesday, April 23, 2013 2:29 AM
  •  

    Sorry, moved to other projects and for some reason did not get email notification on this issue, to check it earlier.

    Yes, I do have zipped sample app, the source, and release exe, with XPS test file to demo the issue. Please let me know where to submit this ZIP.

    Monday, May 20, 2013 3:30 AM