Presentation-to-PDF Conversion with a Diagram Including Custom Date Formats

Hi Aspose team,

we aim to convert a pptx document into a pdf document using Aspose.Slides but having an issue with a custom date format used in a diagram within the pptx.

Please find attached a zip file including the following documents:

  1. Sample.pptx: The original pptx document
  2. Ppt_save_as_PDF.pdf: A pdf generated using Powerpoints “Save as” → “PDF” functionality
  3. Print_to_PDF.pdf: A pdf generated using Powerpoints/Windows’ “Print → Microsoft Print to PDF” functionality
  4. Aspose_save_as_PDF.pdf: A pdf generated using the following Aspose-code
// register licence ...
Aspose.Slides.Presentation p = new Aspose.Slides.Presentation(@"<path>\Sample.pptx");
p.Save(@"<path>\Aspose_save_as_PDF.pdf", Aspose.Slides.Export.SaveFormat.Pdf);

Issue:
Documents #1-3 display the x-axis labels properly by showing “Jan 25”, “Feb 25” and “Mar 25”, whereas Aspose.Slides converts these values into numbers (45658, 45689 and 45717 respectively) as can be seen in document #4.

The original pptx document has been created using the Powerpoint feature “Insert”->“Chart” and then by formatting the data cells (of the x-axis) to display a custom date format “MMM JJ”. (You can right-click the chart and select “edit data” to view the underlying spreadsheet.)

SampleFiles.zip (280.2 KB)

Kind regards,
Matthias

@M.Heinz

Cause

The issue you’re experiencing with Aspose.Slides converting custom date formats in your diagram to numeric values instead of displaying them as formatted dates is likely due to how Aspose.Slides interprets chart data from PowerPoint presentations. When the chart data is extracted, the custom formatting may not be preserved, leading to the display of numeric values instead.

Solution

To resolve this, you can manually format the x-axis labels after loading the presentation. You will need to access the chart data and set the labels to the desired date format programmatically. Here’s how you can do this:

Code

// Load the presentation
Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation("Sample.pptx");

// Access the first slide
ISlide slide = presentation.getSlides().get_Item(0);

// Access the chart
IChart chart = (IChart) slide.getShapes().get_Item(0);

// Access the x-axis
IAxis xAxis = chart.getAxes().getPrimaryCategoryAxis();

// Set custom date format for x-axis labels
for (int i = 0; i < xAxis.getLabels().size(); i++) {
    // Assuming you have a method to convert the numeric value to the desired date format
    String formattedDate = convertToCustomDateFormat(xAxis.getLabels().get_Item(i).getText());
    xAxis.getLabels().get_Item(i).setText(formattedDate);
}

// Save the presentation as PDF
presentation.save("Aspose_save_as_PDF.pdf", SaveFormat.Pdf);

Make sure to implement the convertToCustomDateFormat method to convert the numeric values to your desired date format.

Next Steps

  1. Implement the date conversion logic in the convertToCustomDateFormat method.
  2. Test the code to ensure the x-axis labels display correctly in the generated PDF.
  3. If you encounter any further issues, please reach out for additional assistance.

This should effectively resolve the issue with the date formatting. Let me know if you need any further help!

This suggestion is not a desirable solution, because we don’t hard-code the format of the x-axis labels. Those labels might as well be static strings, numbers (intentionally) or even other custom formats for a given set of data.

Customers of ours create their pptx documents and our software needs to be able to display them as PDF documents regardless of their contents. As such, saving an Aspose.Slides.Presentation via the Save function should automatically respect said formatting, as does

  • Powerpoint when saving the pptx as pdf
  • as well as Microsoft Print to PDF.

@M.Heinz,

Thanks for the sample PowerPoint presentation document and PDF files.

After initial testing, I was able to reproduce the issue as you mentioned by converting your PowerPoint presentation file to PDF. I found date formatting for x-axis labels of the chart is not applied in the output PDF.

We require though evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESNET-45043

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

The issues you found earlier (filed as SLIDESNET-45043) have been resolved in Aspose.Slides for .NET 25.9 (ZIP, MSI, NuGet, Cross-platform).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page.