Skip to content

Commit 91d4c8b

Browse files
committed
addressed the feedback
1 parent 1ce8808 commit 91d4c8b

File tree

1 file changed

+56
-5
lines changed

1 file changed

+56
-5
lines changed

knowledge-base/export-charts-to-pdf-radspreadprocessing.md

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Learn how to export charts from Excel files to PDF format using Rad
44
type: how-to
55
page_title: How to Export Charts from Excel to PDF with RadSpreadProcessing and WinForms RadChartView
66
slug: export-charts-to-pdf-radspreadprocessing
7-
tags: spreadprocessing, document, processing, export, chart, pdf, excel, image, winforms
7+
tags: spreadprocessing, document, processing, export, chart, pdf, excel, image, winforms, sheet, worksheet, xslx
88
res_type: kb
99
ticketid: 1659898
1010
---
@@ -17,7 +17,7 @@ ticketid: 1659898
1717

1818
## Description
1919

20-
When converting an Excel file with charts to PDF, the charts may not display as expected in the PDF document. This may occur when exporting charts to PDF in .NET Framework applications. This KB article shows a sample approach how to utilize the chart engine that [WinForms RadChartView]({%slug winforms/chartview/overview%}) control offers and ensure charts are properly exported from Excel files to PDF.
20+
When converting an Excel file with charts to PDF format using the Telerik Document Processing libraries, the charts may not display as expected in the PDF document. This may occur when exporting charts to PDF in .NET Framework applications. This KB article shows a sample approach how to utilize the chart engine that [WinForms RadChartView]({%slug winforms/chartview/overview%}) control offers and ensure charts are properly exported from Excel files to PDF.
2121

2222
## Solution
2323

@@ -32,13 +32,22 @@ To export charts from Excel files to PDF format using RadSpreadProcessing, follo
3232
Below is a sample implementation using the WinForms RadChartView for chart visualization:
3333

3434
```csharp
35+
using System.IO;
36+
using Telerik.Windows.Documents.Fixed.Model.Editing;
37+
using Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.Export;
38+
using Telerik.Windows.Documents.Spreadsheet.Model.Shapes;
39+
3540
public class WinFormsPdfChartImageRenderer : IPdfChartRenderer
3641
{
42+
public WinFormsPdfChartImageRenderer()
43+
{
44+
}
45+
3746
public void RenderChart(FixedContentEditor editor, FloatingChartShape chartShape)
3847
{
3948
string filePath = @"exportedChart.png";
4049

41-
System.Drawing.Size size = new System.Drawing.Size((int)(chartShape.Width ),(int)(chartShape.Height));
50+
System.Drawing.Size size = new System.Drawing.Size((int)(chartShape.Width), (int)(chartShape.Height + 10));
4251
System.Drawing.Image chartImage = Telerik.WinForms.Controls.Spreadsheet.Layers.ChartModelToImageConverter.GetImageFromFloatingChartShape(chartShape, size);
4352

4453
chartImage.Save(filePath);
@@ -49,11 +58,53 @@ public class WinFormsPdfChartImageRenderer : IPdfChartRenderer
4958
File.Delete(filePath);
5059
}
5160
}
61+
```
62+
63+
Using the custom chart renderer:
5264

53-
PdfFormatProvider pdfFormatProvider = new PdfFormatProvider();
54-
pdfFormatProvider.ExportSettings.ChartRenderer = new WinFormsPdfChartImageRenderer();
65+
```csharp
66+
Workbook workbook;
67+
IWorkbookFormatProvider xlsxFormatProvider = new XlsxFormatProvider();
68+
69+
using (Stream input = new FileStream("spreadsheetWithChart.xlsx", FileMode.Open))
70+
{
71+
workbook = xlsxFormatProvider.Import(input);
72+
}
73+
74+
WorksheetPageSetup pageSetup = workbook.ActiveWorksheet.WorksheetPageSetup;
75+
pageSetup.PaperType = PaperTypes.A4;
76+
77+
PdfFormatProvider pdfFormatProvider = new PdfFormatProvider();
78+
pdfFormatProvider.ExportSettings.ChartRenderer = new WinFormsPdfChartImageRenderer(); // new WpfPdfChartImageRenderer();
79+
80+
string outputFilePath = "spreadsheetWithChart.pdf";
81+
File.Delete(outputFilePath);
82+
using (Stream output = File.OpenWrite(outputFilePath))
83+
{
84+
pdfFormatProvider.Export(workbook, output);
85+
}
86+
87+
var psi = new ProcessStartInfo()
88+
{
89+
FileName = outputFilePath,
90+
UseShellExecute = true
91+
};
92+
Process.Start(psi);
5593
```
5694

95+
### Required Assemblies
96+
97+
* Telerik.WinControls.RadSpreadsheet
98+
* Telerik.WinControls
99+
* Telerik.WinControls.ChartView
100+
* Telerik.WinControls.UI
101+
* TelerikCommon
102+
* Telerik.Windows.Documents.Core
103+
* Telerik.Windows.Documents.Fixed
104+
* Telerik.Windows.Documents.Spreadsheet
105+
* Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml
106+
* Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf
107+
57108
## See Also
58109

59110
- [RadSpreadProcessing Overview]({%slug radspreadprocessing-overview%})

0 commit comments

Comments
 (0)