Jump to content
Software FX Community

XPS Serialization


johnt

Recommended Posts

I'm evaluating ChartFX for WPF for an application that generates reports. We are trying to create report pages in XAML and then export them to XPS documents. It has worked very well except we've had trouble getting charts to work right (not just ChartFX...). When the charts are written to the XPS document, only the borders/background of the chart appear. The main pane, axes, series, etc. do not show. I saw a similar problem that happened when printing charts that were not visually displayed so it may be related.

Here is some sample code that reproduces this. I place the chart control in a FixedDocument and then write that document using XpsDocumentWriter.Write(Visual visual). The chart appears fine when the document is displayed in a document viewer, but it is not correct in the XPS file which leads me to believe its only an issue when "drawing" the chart in the XpsDocumentWriter.

 

 Size pageSize = new Size(96 * 8.5, 96 * 11);

// create the fixed pageFixedPage fixedPage = new FixedPage();fixedPage.Background = Brushes.White;

fixedPage.Width = pageSize.Width;

fixedPage.Height = pageSize.Height;

// add the chart controlChart chart = new Chart();

chart.Background =

new SolidColorBrush(Colors.Green);FixedPage.SetLeft(chart, 96 * 0.75);FixedPage.SetTop(chart, 96 * 0.75);

chart.Width = 300;

chart.Height = 300;

fixedPage.Children.Add((UIElement)chart);

// update sizes

fixedPage.Measure(pageSize);

fixedPage.Arrange(new Rect(new Point(), pageSize));

fixedPage.UpdateLayout();

// create the documentFixedDocument document = new FixedDocument();

document.DocumentPaginator.PageSize = pageSize;

PageContent pageContent = new PageContent();((IAddChild)pageContent).AddChild(fixedPage);

document.Pages.Add(pageContent);

// save as xpsstring fileName = "chart.xps";

Package package = Package.Open(fileName, FileMode.Create);XpsDocument xpsDocument = new XpsDocument(package);XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument);

xpsWriter.Write(document);

package.Flush();

package.Close();

Link to comment
Share on other sites

We have fixed this issue on our internal builds although you will need an additional line of code for charts that won't be displayed on the screen but only used for XPS generation.

chart.AdvancedSettings |=

ChartSettings.RenderBeforeLoad;

Send an email to support at softwarefx dot com if you want to test this before it is released.

Regards,

JuanC

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...