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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Export Pie Chart to PDF

Thread ID:





142290 Jan 25,2019 07:26 AM UTC Mar 19,2019 05:29 AM UTC WPF 6
Tags: SfChart
Asked On January 25, 2019 07:26 AM UTC

Hi Team,

I'm using sfchart component in my WPF project, and want to export sfchart to PDF, But i'm unable to do it. Please help me on this issue.
I have also attached a sample. Please add "Export to PDF" functionality on it. 


Attachment: DynamicDataPieChart_404741cd.rar

Muneesh Kumar G [Syncfusion]
Replied On January 25, 2019 09:48 AM UTC

Hi Brijesh,   
Greetings, we have analyzed your requirement but unfortunately, we were unable to extract the attachment in your update.  
However, you can export the SfChart to PDF by getting stream of SfChart, then preparing PdfDocument with that stream as per the below code snippet.  
Code snippet 
  private void ChartToPDF() 
            MemoryStream outStream = new MemoryStream(); 
            chart.Save(outStream, new BmpBitmapEncoder()); 
            PdfPage page = pdfDoc.Pages.Add(); 
            PdfBitmap img = new PdfBitmap(outStream); 
            page.Graphics.DrawImage(img, 0, 0, 500, 250); 
        private void SavePDF(string pdfFile) 
        private void Button_Click(object sender, RoutedEventArgs e) 
            pdfDoc = new PdfDocument(); 
We have prepared a sample based on this, please find the sample from the following location.  
Hope it helps you.  
Muneesh Kumar G.  

Replied On January 28, 2019 09:26 AM UTC

Hi Muneesh,

Thank you for your answer, and it worked for me.
But still i'm facing couple of issues regarding SfChart when it is exported to PDF file. 
     1) It always give black background of SfChart(when PDF is created successfully).
     2) How to make SfChart to fit in PDF page.

I have also attached a sample. I hope this time it will work.


Attachment: DynamicPieChart_dfea0931.zip

Bruno Fernando Rodrigues
Replied On January 28, 2019 06:53 PM UTC

I've the same question.

Muneesh Kumar G [Syncfusion]
Replied On January 29, 2019 04:22 AM UTC

Hi Brijesh, 
We have analyzed your queries and prepared the required solutions. 
Query 1: It always give black background of SfChart(when PDF is created successfully). 
The default background for the SfChart is transparent, so the background appears black in PDF conversion. This can be overcome by setting white Background color for the chart as per the below code snippet. 
Code Snippet 
        <syncfusion:SfChart Background="White"> 
Query 2: How to make SfChart to fit in PDF page. 
To make the chart fit in the pdf page, you have to set SfChart size and PdfGrphics (page.Graphics) size as same. 
        <syncfusion:SfChart Width="300" Height="200"> 
        private void ChartToPDF() 
            page.Graphics.DrawImage(img, 0, 0, 300, 200); 
SfChart HorzontalAlignment must be left and VerticalAlignment must be top. 
        <syncfusion:SfChart HorizontalAlignment="Left" VerticalAlignment="Top"> 
If margin is applied for the SfChart, twice the displacement has to be given for the PdfGraphics x and y position. 
private void ChartToPDF() 
            page.Graphics.DrawImage(img, (float)(-ChartMargin.Left * 2) - AdjustmentCoefficient, (float)(-ChartMargin.Top * 2) - AdjustmentCoefficient, 300, 200); 
We have modified the sample as per your requirement. 
Muneesh Kumar G.

Victor Faria
Replied On March 19, 2019 12:36 AM UTC

So it's not possible to export na image diferente from it's screen size?

Muneesh Kumar G [Syncfusion]
Replied On March 19, 2019 05:29 AM UTC

Hi Brijesh, 
We have analyzed your requirement and you can achieve this by setting Height, Width for SfChart as per the below code snippet.  
Code snippet 
<Grid > 
            <RowDefinition Height="8*"/> 
            <RowDefinition Height="2*"/> 
        <Button Content="Save" Click="Button_Click" Height="30" Width="70"  
        <chart:SfChart   x:Name="chart"  Background="White" Height="300" Width="600"    
Also, exporting rendering from (0,0) position. So, SfChart HorizontalAlignment must be left and VerticalAlignment must be top.  
Exported Path:  ...\WPF_Sample\Sample\bin\Debug 
Exported image:  
Please let us know if you have any queries.  
Muneesh Kumar G.  


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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