public async void ExportAsPDF(string filename, Stream chartStream, SfChart chart) { NativeChart.SfChart nativeChart = SfChartRenderer.GetNativeObject(typeof(SfChart), chart) as NativeChart.SfChart; StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFile file = await localFolder.CreateFileAsync("filename", CreationCollisionOption.ReplaceExisting); if (file != null) { IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite); await Save_UWP(nativeChart, stream); } using (var fileStream = await file.OpenAsync(FileAccessMode.Read)) { var reader = new DataReader(fileStream.GetInputStreamAt(0)); var bytes = new byte[fileStream.Size]; await reader.LoadAsync((uint)fileStream.Size); reader.ReadBytes(bytes); MemoryStream imageStream = new MemoryStream(bytes); if (file != null) { var document = new PdfDocument(); var page = document.Pages.Add(); var graphics = page.Graphics; PdfBitmap image = new PdfBitmap(imageStream); graphics.DrawImage(image, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height); chartStream = new MemoryStream(); document.Save(chartStream); document.Close(true); Save(chartStream, filename, ".pdf"); } } }
public void ExportAsPDF(string filename, Stream chartStream, SfChart chart) { try { //Create a new PDF document. var document = new PdfDocument(); var page = document.Pages.Add(); var graphics = page.Graphics; graphics.DrawImage(PdfImage.FromStream(chartStream), 0, 0, page.GetClientSize().Width, page.GetClientSize().Height); MemoryStream stream = new MemoryStream(); document.Save(stream); document.Close(true); SavePDF(filename, stream); } finally { chartStream.Flush(); chartStream.Close(); var nativeChart = SfChartRenderer.GetNativeObject(typeof(SfChart), chart); ((Com.Syncfusion.Charts.SfChart)nativeChart).DrawingCacheEnabled = false; } }