Chart.ToPdf

ToPdf(string)

Saves the chart to a pdf file.

public void ToPdf(string fileName)
ParameterTypeDescription
fileNameStringthe pdf file name with full path

Examples

using System;
using Aspose.Cells;
using Aspose.Cells.Charts;

namespace AsposeCellsExamples
{
    public class ChartMethodToPdfWithStringDemo
    {
        public static void Run()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();
            
            // Access first worksheet and add sample data
            Worksheet worksheet = workbook.Worksheets[0];
            worksheet.Cells["A1"].PutValue("Category");
            worksheet.Cells["A2"].PutValue("Fruits");
            worksheet.Cells["A3"].PutValue("Vegetables");
            worksheet.Cells["B1"].PutValue("Value");
            worksheet.Cells["B2"].PutValue(50);
            worksheet.Cells["B3"].PutValue(30);

            // Add a chart to the worksheet
            int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 20, 8);
            Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
            
            // Set chart data source
            chart.NSeries.Add("B2:B3", true);
            chart.NSeries.CategoryData = "A2:A3";

            // Export chart to PDF
            chart.ToPdf("output_chart.pdf");
            
            Console.WriteLine("Chart exported to PDF successfully.");
        }
    }
}

See Also


ToPdf(string, float, float, PageLayoutAlignmentType, PageLayoutAlignmentType)

Saves the chart to a pdf file.

public void ToPdf(string fileName, float desiredPageWidth, float desiredPageHeight, 
    PageLayoutAlignmentType hAlignmentType, PageLayoutAlignmentType vAlignmentType)
ParameterTypeDescription
fileNameStringthe pdf file name with full path
desiredPageWidthSingleThe desired page width in inches.
desiredPageHeightSingleThe desired page height in inches.
hAlignmentTypePageLayoutAlignmentTypeThe chart horizontal alignment type in the output page.
vAlignmentTypePageLayoutAlignmentTypeThe chart vertical alignment type in the output page.

Examples

using System;
using Aspose.Cells;
using Aspose.Cells.Charts;

namespace AsposeCellsExamples
{
    public class ChartMethodToPdfWithStringSingleSinglePageLayoutAlDemo
    {
        public static void Run()
        {
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            worksheet.Cells["A1"].PutValue("Data");
            worksheet.Cells["A2"].PutValue(10);
            worksheet.Cells["A3"].PutValue(20);
            worksheet.Cells["A4"].PutValue(30);

            int chartIndex = worksheet.Charts.Add(ChartType.Column, 5, 0, 15, 5);
            Chart chart = worksheet.Charts[chartIndex];
            chart.SetChartDataRange("A1:A4", true);
            chart.Title.Text = "Demo Chart";

            chart.ToPdf("ChartDemo.pdf", 8.5f, 11f, PageLayoutAlignmentType.Center, PageLayoutAlignmentType.Center);
        }
    }
}

See Also


ToPdf(Stream)

Creates the chart pdf and saves it to a stream.

public void ToPdf(Stream stream)
ParameterTypeDescription
streamStreamThe output stream.

See Also


ToPdf(Stream, float, float, PageLayoutAlignmentType, PageLayoutAlignmentType)

Creates the chart pdf and saves it to a stream.

public void ToPdf(Stream stream, float desiredPageWidth, float desiredPageHeight, 
    PageLayoutAlignmentType hAlignmentType, PageLayoutAlignmentType vAlignmentType)
ParameterTypeDescription
streamStreamThe output stream.
desiredPageWidthSingleThe desired page width in inches.
desiredPageHeightSingleThe desired page height in inches.
hAlignmentTypePageLayoutAlignmentTypeThe chart horizontal alignment type in the output page.
vAlignmentTypePageLayoutAlignmentTypeThe chart vertical alignment type in the output page.

See Also