Pre loader

How to print Usercontrol with scichartsurface and ohter wpf controls to PDF?

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

1
0

I have a UserControl which contains a chart and some wpf controls. How can I print this UserControl to PDF or XPS? All examples I see are for the chart only.

Version
1.4
  • You must to post comments
1
0

Hi,

I’m sorry for the late reply.
We discussed your inquiry.

If you want to print a View that was rendered, you could use WPF PrintDialog API. Here you can find more details:
PrintDialog.PrintVisual(Visual, String) Method (System.Windows.Controls) _ Microsoft Learn

However, if the View wasn’t rendered before you initialize printing this approach won’t work.
The only way to print the View would be exporting SciChartSurface to a bitmap using SciChart Export API, then inserting this Bitmap onto the View as an Image.

Unfortunately, there isn’t any easier solution for this case out of the box at the moment.

Kind regards,
Lex,
SciChart Technical Support Engineer

  • You must to post comments
1
0

Thank you for your response.
I tried your suggestion and I export the SciChartSurface to a bitmap which works fine. However, there is a memory leak in the ExportToBitmapSource API. Below you can see my code. If I remove the line ” pdfview.cChart.SciChart.ExportToBitmapSource(useXamlRenderSurface, exportedSize);” then there is no memory leak. Am I doing something wrong or is this caused due to the API?

MemoryStream lMemoryStream = new MemoryStream();
Package package = Package.Open(lMemoryStream, FileMode.Create);
XpsDocument doc = new XpsDocument(package);
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
PDFView pdfview = new PDFView();
pdfview.DataContext = this;

pdfview.Arrange(new Rect(0, 0, 1800, 1080));

bool useXamlRenderSurface = false;
Size? exportedSize = null;

// Export to BitmapSource at size
imgSource = pdfview.cChart.SciChart.ExportToBitmapSource(useXamlRenderSurface, exportedSize);

//dispose to avoid memory leak
((XyDataSeries<double, double>)pdfview.cChart.SciChart.RenderableSeries[0].DataSeries).Clear();
((XyDataSeries<double, double>)pdfview.cChart.SciChart.RenderableSeries[1].DataSeries).Clear();
((XyDataSeries<double, double>)pdfview.cChart.SciChart.RenderableSeries[2].DataSeries).Clear();
((XyDataSeries<double, double>)pdfview.cChart.SciChart.RenderableSeries[3].DataSeries).Clear();
((XyDataSeries<double, double>)pdfview.cChart.SciChart.RenderableSeries[4].DataSeries).Clear();
pdfview.cChart.SciChart.RenderableSeries.Clear();
pdfview.cChart.SciChart.RenderableSeries = null;
pdfview.cChart.SciChart.Dispose();
pdfview.cChart.SciChart = null;
pdfview.cChart = null;
pdfview = null;
imgSource = null;

  • Lex
    Hi, Thanks for your reply. Unfortunately, the provided information is not enough to determine the exact cause of the reported issue. We would appreciate if you could share a small sample project reproducing this for investigation on our side. Thanks in advance, Lex
  • You must to post comments
1
0

You can download a reproduction from here: [redacted]

Click multiple times on the Print button to see the memory go up.

  • Andrew Burnett-Thompson
    Hey, you’ve just uploaded what looks like your entire app to Google drive and shared it here publicly. I’ve removed the google drive link because you could inadvertently share your company’s IP. If you require support from us then you will need to do two things. (1) ensure that you provide a minimal solution to reproduce the problem, not an entire application. (2) next, your license is showing as support-expired in 2022. Your company will need to renew it and have an up-to-date support subscription in order to access technical support for SciChart. Best regards, Andrew
  • j chatlein
    This is not the real app. This is the minimal solution to reproduce the problem. I think it is a large size because I forgot to remove the nuget packages, the app itself is very small. However, I do not need support anymore. I moved back to use Oxyplot which does not have this issue. But I thought it would be good for SciChart to know this if it indeed is leaking memory due to a bug.
  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.