Click here to Skip to main content
16,017,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

i was generation XPS report with wpf and displaying with document viewer.the report is showing fine in document viewer

but when i save this report and try to open in IE(InternetExplorer)/third partuy XPS viewer it is showing a error.here iam attaching my

Code and Error:

Code:
C#
FixedDocument fixedDocument= new FixedDocument ();

FixedPage fixedpage = new FixedPage {Height = 840,Width = 800};
      PageContent pageContent = new PageContent();
      ((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedpage);
      fixedDocument.Pages.Add(pageContent);
    DrawingVisual  visual = new DrawingVisual();
      drawingContext = visual.RenderOpen();

drawingContext.DrawText(new FormattedText(text,CultureInfo.GetCultureInfo("en-us"),
                                                FlowDirection.LeftToRight,font,
                                                font.Size,brush),new Point(rect.X,rect.Y));

  drawingContext.Close();
      UIElement ui = new DrawingVisualPresenter(visual);//DrawingVisualPresenter is used to convert visual to UIElement we can add only T                                                                                         //UIElement to fixedpage

       fixedpage.Children.Add(ui);

XpsDocument xpsDocument = new XpsDocument("XPSReport.xps",FileAccess.ReadWrite);//saving the report XPSReport.xps to bin folder
      XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
      writer.Write(fixedDocument);
       DocumentViewer.Document = xpsDocument .GetFixedDocumentSequence();

internal class DrawingVisualPresenter: FrameworkElement {
    private DrawingVisual visual;
    internal DrawingVisualPresenter(DrawingVisual visual) {
      this.visual = visual;
    }

    protected override int VisualChildrenCount {
      get { return 1; }
    }

    protected override Visual GetVisualChild(int index) {
      if (index != 0)
        throw new ArgumentOutOfRangeException("index");
      return visual;
    }
  }


Error::

HTML
Startup URI: D:\Projects\Cardio\Source\UCTests\bin\Debug\XpsReport.xps
Application Identity:

System.ArgumentException: The document does not contain a valid FixedDocumentSequence.
   at MS.Internal.Documents.DigitalSignatureProvider..ctor(Package package)
   at MS.Internal.Documents.Application.PackageController.MS.Internal.Documents.Application.IDocumentController.Open(Document document)
   at MS.Internal.Documents.Application.DocumentManager.DispatchOpen(IDocumentController controller, Document document)
   at MS.Internal.Documents.Application.DocumentManager.<>c__DisplayClass6.<orderbyleastdependent>b__5(IDocumentController controller, Document subject)
   at MS.Internal.Documents.Application.ChainOfResponsiblity`2.Dispatch(Action action, S subject)
   at MS.Internal.Documents.Application.DocumentManager.<>c__DisplayClass6.<orderbyleastdependent>b__4(Document member)
   at MS.Internal.Documents.Application.ChainOfDependencies`1.OrderByLeastDependent(T member, Action action)
   at MS.Internal.Documents.Application.DocumentManager.OrderByLeastDependent(DispatchDelegate action, Document document)
   at MS.Internal.Documents.Application.DocumentManager.Open(Document document)
   at MS.Internal.AppModel.ApplicationProxyInternal.InitContainer()
   at MS.Internal.AppModel.ApplicationProxyInternal.Run(InitData initData)</orderbyleastdependent></orderbyleastdependent>
Posted
Updated 6-Feb-12 17:38pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900