I installed Spire.Doc to try for using in asp.net mvc application. I need to render charts and to save its for PowerPoint and PDF. I prepare font size for axis and legend before saving(comparison_chart.pptx). I got perfect presentation In PowerPoint but after saving it to pdf (comparison_chart.pdf) legend font size is not set. Pie chart (breakdown_chart.pptx) does not render into pdf at all. The pdf page is clear into breakdown_chart.pdf.
public override object ExportToPPT()
{
Presentation presentation = new Presentation();
//insert chart
RectangleF rect = new RectangleF(presentation.SlideSize.Size.Width / 2 - 300, 50, 600, 400);
Spire.Presentation.Charts.ChartType chartType;
if (ChartSettings is IPieComponent)
chartType = ChartType.Pie;
else
chartType = ChartType.ColumnClustered;
IChart chart = presentation.Slides[0].Shapes.AppendChart(chartType, rect, true);
//add chart Title
chart.ChartTitle.TextProperties.Text = ChartSettings.Title;
chart.ChartTitle.TextProperties.IsCentered = true;
chart.ChartTitle.Height = 30;
chart.HasTitle = true;
//Getting data
DataTable data = PrepareData();
InitChartData(chart, data);
chart.Series.SeriesLabel = chart.ChartData[0,1,0,ChartSettings.Values.Count()];
chart.Categories.CategoryLabels = chart.ChartData[1,0,data.Rows.Count,0];
for (int i = 0; i < chart.Series.Count; i++)
{
chart.Series[i].Values = chart.ChartData[1, 1+i, data.Rows.Count, 1+i];
chart.Series[i].YValues.Add(chart.ChartData[1, 1 + i, data.Rows.Count, 1 + i]);
chart.Series[i].XValues.Add(chart.ChartData[0, 1, 0, ChartSettings.Values.Count()]);
if (ChartSettings.Values.Count() <= 1)
{
//chart.Series[i].IsVaryColor = true;
}
if ((DataSource as DataTable).Columns.IndexOf("CustomColor") >= 0)
{
for (int j = 0; j < chart.Categories.Count; j++)
{
ChartDataPoint dataPoint = new ChartDataPoint(chart.Series[i]);
//Adding cusom color if exist CustomColor field in DataSource
dataPoint.Fill.SolidColor.Color = System.Drawing.ColorTranslator.FromHtml((string)(DataSource as DataTable).Rows[j]["CustomColor"]);
dataPoint.Index = j;
dataPoint.Fill.FillType = FillFormatType.Solid;
chart.Series[i].DataPoints.Add(dataPoint);
}
}
}
chart.ChartLegend.setEntrys(chart.ChartData[1, 0, 1 + data.Rows.Count - 1, chart.Series.Count]);
foreach (var legendEntryTextProp in chart.ChartLegend.EntryTextProperties)
{
legendEntryTextProp.FontHeight = 9;
}
if (chart.PrimaryCategoryAxis != null)
chart.PrimaryCategoryAxis.TextProperties.Paragraphs[0].DefaultCharacterProperties.FontHeight = 9;
if(chart.PrimaryValueAxis != null)
chart.PrimaryValueAxis.TextProperties.Paragraphs[0].DefaultCharacterProperties.FontHeight = 10;
return presentation;
}
public override object ExportToPDF()
{
PdfDocument pdf = new PdfDocument();
Presentation presentation = ExportToPPT() as Presentation;
MemoryStream stream = new MemoryStream();
presentation.SaveToFile(stream, Spire.Presentation.FileFormat.PDF);
pdf.LoadFromStream(stream);
return pdf;
}