Word Wrapping Issue in Chart Legends When Converting PPTX to PDF in Java

Hi,

I am using PPTx to PDF conversion using Aspose and I am able to stop wrapping in legends in PPTx, however in the generated PDF the legend is wrapping. And this is what am using

  com.aspose.slides.ILegend legend = chart.getLegend();
  if ( legend != null )
  {
    legend.setOverlay( false );
    legend.setPosition( com.aspose.slides.LegendPositionType.Right );
    legend.setTextWrapType(com.aspose.slides.TextWrapType.None);

Could you please guide us here with this wrap issue

@ysomaraju

Cause

It appears that even though you’ve set the TextWrapType to None for the chart legend in your PPTX file, the generated PDF still displays the legend text wrapping. This issue can arise due to differences in text rendering between the PPTX and PDF formats.

Solution

To prevent the legend text from wrapping in the generated PDF, you should explicitly adjust the legend’s width. By setting a fixed width for the legend, you can ensure that the text remains unwrapped. Here’s how you can implement this:

Code

// Access the chart and its legend
com.aspose.slides.ILegend legend = chart.getLegend();
if (legend != null) {
    legend.setOverlay(false);
    legend.setPosition(com.aspose.slides.LegendPositionType.Right);
    legend.setTextWrapType(com.aspose.slides.TextWrapType.None);
    
    // Set a fixed width for the legend
    legend.setWidth(200); // Adjust the width as necessary
}

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

Next Steps

  1. Adjust the width value based on your specific needs to ensure the legend fits without wrapping.
  2. Test the PDF generation again to confirm that the issue is resolved.
  3. If the problem persists, review any other settings or properties that might influence the legend’s appearance.

Please implement these changes and let me know if you need further assistance!

legend.setWidth(200); is not working, still the wrap is on

@ysomaraju,

Could you please zip the PPTX and PDF files and share the archive here. We’ll evaluate your issue soon.

Aspose.zip (63.3 KB)

Thanks Amjad, attached zip with PPTx and PDF. Please suggest your inputs

@ysomaraju,

Thanks for the sample files.

I was able to reproduce the issue as you mentioned by converting your template PowerPoint presentation file to PDF. I found, in the generated PDF, some legend items are wrapping unnecessarily for the Pie chart. It should display legend items as shown in MS PowerPoint app.

Presentation presentation = new Presentation("d:\\files\\LW Story Board.pptx");
presentation.save("d:\\files\\output1.pdf" , com.aspose.slides.SaveFormat.Pdf);

We require thorough 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): SLIDESJAVA-39691

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.

Thanks amjad, we are in the process of buying a license, may be few days from now, so is there any other way of raising defect to get that addressed

@ysomaraju,

In our standard support forum, we address issues on a first-come, first-served basis, as we believe this is the fairest approach. If your issue is particularly urgent, you may consider paid support for prioritized resolution. We kindly ask for a little time to thoroughly evaluate your issue, after which we will provide you with the latest updates or an estimated timeline for resolution. Please rest assured that we are committed to resolving your issue soon (if possible).

Thanks Amjad, this helps

@ysomaraju,

You are welcome. We will keep you posted with new updates (once available) on your issue.

The issues you found earlier (filed as SLIDESJAVA-39691) have been resolved in Aspose.Slides for Java 25.8 (Maven, JAR).
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.