Category / Section
How to apply the PDF document size to Xamarin.Forms Chart?
1 min read
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);