)
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. (Last updated on: June 24, 2019).
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 |
Published Date: April 16, 2018 |
Last Revised Date: August 21, 2019

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.

 

C#:

 

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.
ADD COMMENT
You must log in to leave a comment
Comments
dev clinicea
Jan 17, 2020

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

Reply

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
Live Chat Icon