We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to apply the PDF document size to Xamarin.Forms Chart?

Platform: Xamarin.Forms |
Control: SfChart

Chart can be exported to pdf with the help of GetStream method of SfChart and DependencyService. Set the required size to chart before getting it as stream and pass it to pdf document. If you want to stretch the chart in pdf document, set the size of pdf document to chart using WidthRequest and HeightRequest properties of SfChart. Please refer the below code snippets to set the size of pdf document to chart and getting the stream of chart.




var document = new PdfDocument();
chart.WidthRequest = document.PageSettings.Width;
chart.HeightRequest = document.PageSettings.Height;
var stream = chart.GetStream();
var page = document.Pages.Add();
var graphics = page.Graphics;
graphics.DrawImage(PdfImage.FromStream(stream), 0, 0, page.GetClientSize().Width, page.GetClientSize().Height);
DependencyService.Get<IChartDependencyService>().SaveAsPDF("Chart.pdf", stream, chart, document);



2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
You must log in to leave a comment
dev clinicea
Jan 17, 2020

If 1 contentpage has multiple charts, how do we export all of them to PDF? Tx.

Jul 06, 2021

This is very useful and displays the chart in the correct size on the PDF. However the scaling of the chart is all wrong, it is literally outputted as a stretched version of whatever was on screen, rather than being rendered correctly for the PDF size. This also means that, for example, if the user has zoomed in on the chart, this view is what is exported rather than the full version of the chart. I would be interested in knowing if there is a way of achieving the above but with the chart rendered correctly for it's new PDF size.


Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile