Export chart does not render the chart size correctly

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


5 Replies

YP Yuvaraj Palanisamy Syncfusion Team July 7, 2021 04:04 PM UTC

Hi William, 
 
Greetings from Syncfusion. 
 
This is a general update to let you know that our support team has taken out your query and they are starting to work on it. We will share the possible solution with validated details on or before July 8th, 2021 EOD.  
 
Regards, 
Yuvaraj. 



YP Yuvaraj Palanisamy Syncfusion Team July 8, 2021 05:02 PM UTC

Hi William, 
 
Thanks for your patience. 
 
We have checked with reported query and we would like to suggest that the issue has been resolved by setting for Width and height of the page as per the below code example. 
 
CodeSnippet: 
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); 
} 
 
 
Also, we have attached the complete sample for your reference. Please find the sample from the below link. 
 
  
Output: 
 
 
 
 
Please let us know if you have any concern. 
 
Regards, 
Yuvaraj. 



WI William July 22, 2021 04:58 PM UTC

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



YP Yuvaraj Palanisamy Syncfusion Team July 25, 2021 06:03 AM UTC

Hi William,

Currently we are validating this, and we will update you with complete details on or before 27th July 2021. We appreciate your patience until then.
 
  
Regards, 
Yuvaraj 



YP Yuvaraj Palanisamy Syncfusion Team July 27, 2021 02:00 PM UTC

Hi William,

Thanks for your patience.

On further analysis, while the exported chart to pdf we have set the page width and height to the drawable image. Hence, the actual chart size is smaller than the page width and height. Due to this the exported pdf chart has been stretched. To resolve this, rendering the exported image with the default width and height of the Pdf page. Please find the code example below.
 
 
CodeSnippet: 
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); 
} 
 
Also, we have attached the sample for your reference. Please find the sample from the below link. 
 
  
Output: [Exported image] 
 
 
Regards, 
Yuvaraj. 


Loader.
Up arrow icon