We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Saving to PDF - Chart tickmark labels alignment change


I have an alignment problem with charts category axis tickmark labels when saving an Excel workbook to PDF.

I am using Aspose.Cells for .Net to add a chart to an Excel file and I then save the resulting workbook to a PDF file.

In this chart, the category axis is a list of dates and its tickmark labels are rotated 45 degrees.

In the Excel file, the tickmark labels are aligned so the end of the text end at the tickmark position (Excel default alignment). My problem is that when the workbook is saved to PDF the tickmark label alignment change and the label text is now centered on the tickmark.

Is there a way to keep the tickmark labels alignment the same when saving to PDF as it is in Excel (or to set options so that the result is the same)?

In the following attachment you can find the TestChartResult.xlsx and TestChartResult.pdf sample files that show the result if saved to Excel (look at the Chart1 sheet to see the chart) or to PDF. You can see the difference when comparing the chart in both files.

TestChart.zip (28.4 KB)

Attached, is also a sample base file (TestChart.xlsx) in which I add the chart using the following code :

        Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(@"C:\TestChart.xlsx");

        Aspose.Cells.Worksheet chartSheet = workbook.Worksheets[workbook.Worksheets.Add()];
        chartSheet.PageSetup.Orientation = Aspose.Cells.PageOrientationType.Landscape;
        chartSheet.PageSetup.LeftMargin = 1.25D;
        chartSheet.PageSetup.TopMargin = 0.65D;
        chartSheet.PageSetup.RightMargin = 0.25D;
        chartSheet.PageSetup.BottomMargin = 0.5D;

        chartSheet.Name = "Chart1";

        int indexChart = chartSheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 2, 0, 35, 10);

        chartSheet.Charts[indexChart].Type = Aspose.Cells.Charts.ChartType.ScatterConnectedByLinesWithoutDataMarker;

        chartSheet.Charts[indexChart].NSeries.Add("='Data'!$C$2:$C$7", true);
        chartSheet.Charts[indexChart].NSeries.Add("='Data'!$D$2:$D$7", true);
        chartSheet.Charts[indexChart].NSeries[0].Name = "='Data'!$C$2";
        chartSheet.Charts[indexChart].NSeries[1].Name = "='Data'!$D$2";

        chartSheet.Charts[indexChart].NSeries.CategoryData = "='Data'!$B$3:$B$7";

        chartSheet.Charts[indexChart].CategoryAxis.CategoryType = Aspose.Cells.Charts.CategoryType.TimeScale;
        chartSheet.Charts[indexChart].CategoryAxis.TickLabels.NumberFormat = "yyyy-MM-dd";
        chartSheet.Charts[indexChart].CategoryAxis.TickLabels.RotationAngle = 45;

        chartSheet.Charts[indexChart].CategoryAxis.BaseUnitScale = Aspose.Cells.Charts.TimeUnit.Days;
        chartSheet.Charts[indexChart].CategoryAxis.MajorUnit = 1;


        foreach (Aspose.Cells.Worksheet ws in workbook.Worksheets)
            if (!ws.Name.Contains("Chart"))
                ws.IsVisible = false;

        workbook.Save(@"C:\TestChartResult.pdf", Aspose.Cells.SaveFormat.Pdf);

Any help would be greatly appreciated.

Thanks, Andre


I have noticed that labels are not aligned center with latest version of Aspose.Cells. Please try our latest version/fix: Aspose.Cells for .NET v19.3.2:

Aspose.Cells19.3.2 For .Net4.0.Zip (4.9 MB)
Aspose.Cells19.3.2 For .Net2.Zip (4.8 MB)
Aspose.Cells19.3.2 For .Net2_AuthenticodeSigned.Zip (4.8 MB)

I have attached output PDF file created by this version.
TestChart_Result.pdf (15.2 KB)

Let us know your feedback.

Yes, thank you, my subscribtion ended but I have been able to confirm that this is fixed in the latest version.


Good to know that your issue is sorted out by the suggest product version. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.