Hi there!
I am working on exporting an SfChart to an A4 PDF. I have followed the instructions here to set the correct size of the chart before it is exported. However, the chart is then not correctly rendered on the PDF.
For example, this is how the chart is rendered on the mobile device:
When the chart is exported, this view is simply stretched to fill the available space, rather than being re-rendered to look correct (for example, text is stretched, still some labels are missing that could now fit):
This is further demonstrated if the user has interacted with the chart for example before clicking export. Here is an example where the user has zoomed in and then tapped export:
What I would like to achieve is that regardless of screen size or how the chart has been interacted with, the exported chart:
a) Fills the space of the PDF
b) Is rendered new to fit this space, therefore appearing visually optimised
c) As such, ignores any user interaction such as zooming, tapping tooltips etc.
Have I missed something in being able to make this happen? Or is this not possible?
Many thanks
Will
|
private async void ExportAsPDF(object sender, EventArgs e)
{
var chartstream = await chart.GetStreamAsync();
PdfDocument doc = new PdfDocument();
PdfPage page = doc.Pages.Add();
PdfGraphics graphics = page.Graphics;
Stream imageStream = chartstream;
PdfBitmap image = new PdfBitmap(imageStream);
doc.PageSettings.SetMargins(0, 0, 0, 0);
graphics.DrawImage(image, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height);
MemoryStream stream = new MemoryStream();
doc.Save(stream);
doc.Close(true);
await DependencyService.Get<ISave>().SaveAndView("chartnew.pdf", "application/pdf", stream);
}
|
Hi there,
This is the method I am following but as I say rather than the chart being rendered in a nice way to fill the space it simply gets stretched from the on-screen version. Here is an example on a portrait page:
As you can see it is stretched and looks really bad. Ideally I would like the chart to be recalculated to fill the space of the PDF, with no stretching and for example adding axis labels that are auto removed on the screen version due to space.
Many thanks
|
private async void ExportAsPDF(object sender, EventArgs e)
{
var chartstream = await chart.GetStreamAsync();
PdfDocument doc = new PdfDocument();
PdfPage page = doc.Pages.Add();
PdfGraphics graphics = page.Graphics;
Stream imageStream = chartstream;
PdfBitmap image = new PdfBitmap(imageStream);
doc.PageSettings.SetMargins(0, 0, 0, 0);
graphics.DrawImage(image, 0, 0);
MemoryStream stream = new MemoryStream();
doc.Save(stream);
doc.Close(true);
await DependencyService.Get<ISave>().SaveAndView("chartnew.pdf", "application/pdf", stream);
} |