PPTX to PDF: Text is improperly rendered in Linux environment (Java)

Dear Sir,

I met some questions about the Aspose.slide. When I generated the documents into pdf format by Aspose.slide on Linux , some of textbox are wrong,i.g. the font type is incorrect, the word is incomplete. However, when I generated documents into ppt format by Aspose.slide on Linux,the documents are in good condition and there is no questions appeared.

Based on the above information, I analyzed it may because the font file was missed. Please kindly confirm this matter and provide one way to solve this issue. THANK YOU FOR YOUR ASSISTANCE!!!

@ximoon,

Can you please share source file and generated result along with sample code so that we may further investigate to help you out.

Desktop.zip (11.4 KB)
This is my code and files.It is different with Linux and local.

@ximoon,

I have worked with sample code shared by you. For further investigation can you please results which you generated on both local and linux environment. Also please share complete environment details with us.ColumnCount.pdf (40.0 KB)

My local version is Window 10 professional and java 1.8 and aspose.slide 18.9.
My Linux is Cent OS 7 and java 1.8 and aspose.slide 18.9.
This is my font folder.

@ximoon,

I have observed the issue shared by you and like to share that the fonts issue is happening owing to factor that fonts used in your application may not be installed or accessible in machine where the issue is happening. Aspose.Slides use the default rendering font of machine in case the used font is not available. In your case, you have used following code line to add the fonts. But you need to ensure the availability of these fonts for correct rendering.

        paragraphs.get_Item(0).getPortions().get_Item(0).getPortionFormat().setLatinFont(new     FontData("楷体"));
            paragraphs.get_Item(0).getPortions().get_Item(0).getPortionFormat().setEastAsianFont(new FontData("楷体"));

This is my code.I get different files like this when I use this code run on my computer and my server.That server is Linux OS.Can you help me solve this problem?Thanks.

Presentation presentation = new Presentation();
ISlide slide = presentation.getSlides().get_Item(0);

    IAutoShape aShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 300, 300);

    aShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0)
            .getPortionFormat().setLatinFont(new FontData("楷体"));
    aShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0)
            .getPortionFormat().setEastAsianFont(new FontData("楷体"));
    aShape.addTextFrame("阿萨德撒多多风群无若群无而我却奥所大所大所大声道啊实打实大师爱的!");

    ITextFrameFormat format = aShape.getTextFrame().getTextFrameFormat();

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    presentation.save(outputStream, SaveFormat.Pdf);

Desktop.zip (21.1 KB)

@ximoon,

I have observed your sample code and its very simple. The problem is in fonts rendering. You please need to ensure that the font is available on both machines. The second issue lies in your code example where you are setting the text on TextFrame level. Please note that font is set on text portion level. So, if you set the text on TextFrame or Paragraph level, the text formatting done on portion level gets reset. In that case the default font used in presentation theme will be used. I suggest you to please try using following sample code along with ensuring availability of font on remote machine.

Presentation presentation = new Presentation();
ISlide slide = presentation.getSlides().get_Item(0);

    IAutoShape aShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 300, 300);

	ITextFrame textFrame=aShape.addTextFrame("");
    textFrame.getParagraphs().get_Item(0).getPortions().get_Item(0)
            .getPortionFormat().setLatinFont(new FontData("楷体"));
    textFrame.getParagraphs().get_Item(0).getPortions().get_Item(0)
            .getPortionFormat().setEastAsianFont(new FontData("楷体"));

    //aShape.addTextFrame("阿萨德撒多多风群无若群无而我却奥所大所大所大声道啊实打实大师爱的!");

textFrame.getParagraphs().get_Item(0).getPortions().get_Item(0).setText("阿萨德撒多多风群无若群无而我却奥所大所大所大声道啊实打实大师爱的!");

//    ITextFrameFormat format = aShape.getTextFrame().getTextFrameFormat();

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    presentation.save(outputStream, SaveFormat.Pdf);

fonts.png (77.5 KB)
I’m sorry I can’t upload my zip file because my zip is too large.This is my font folder. Am I missing the text file?

@ximoon,

Have you tried using the sample code that I have shared with you using latest Aspose.Slides for Java 19.11? In my sample code, I have shared the possible optimization that could have been done in sample code to set the text on portion level. This in not an API issue but issue of missing fonts on machine where you are performing rendering.

Even, in image that you have shared the font that has been referred in code is not available in list. One more suggestion that I can offer in your case is that you copy all the fonts from machine where rendering is done fine to a accessible directory on your target Linux machine. Then you call that font directory externally in your application and then load presentation to perform rendering.

More importantly, please try using latest Aspose.Slides for Java 19.11 on your end and share if the issue is still reproduced.

I update my code.
FontsLoader.loadExternalFonts(new String[]{“template/fonts”});
Presentation presentation = new Presentation();
ISlide slide = presentation.getSlides().get_Item(0);

    IAutoShape aShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 300, 300);
    ITextFrame textFrame = aShape.addTextFrame("");
    aShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0)
            .getPortionFormat().setLatinFont(new FontData("楷体"));
    aShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0)
            .getPortionFormat().setEastAsianFont(new FontData("楷体"));
    textFrame.getParagraphs().get_Item(0).getPortions().get_Item(0)
            .setText("阿萨德撒多多风群无若群无而我却奥所大所大所大声道啊实打实大师爱的!");
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    presentation.save(outputStream, SaveFormat.Pdf);

But I get files as follows.Desktop.zip (21.1 KB)
I dont think this is my font directory externally problem. Because the remote.pdf some fonts display correctly.And My Aspose.Slide verion is 19.11.

@ximoon,

I have observed the issue shared by you and have created an issue with ID SLIDESJAVA-38006 in our issue tracking system as enhancement to further observe this. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

The issues you have found earlier (filed as SLIDESJAVA-38006) have been fixed in this update.