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.
- j chatlein asked 3 months ago
- You must login to post comments
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
- Lex answered 2 months ago
- You must login to post comments
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;
- j chatlein answered 1 month ago
- last edited 4 weeks ago
-
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 login to post comments
You can download a reproduction from here: [redacted]
Click multiple times on the Print button to see the memory go up.
- j chatlein answered 3 weeks ago
- last edited 3 weeks ago
-
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
-
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 login to post comments
Please login first to submit.