Pptx to PDf loses fonts in empty table cells

I have a table in pptx with a few cells filled in. I replace cells in the table and the one that was empty from the beginning loses the font and size information. The cells that had text from the start are replaces correctly.


I have tested with 14.9 (works), 14.10 (Doesn’t work) and 15.1 (Doesn’t work).

I have attached source, the template and the 3 pdf files generated.

Source is like this:

System.out.println(“os.name=” + System.getProperty(“os.name”));
System.out.println(“os.version=” + System.getProperty(“os.version”));
System.out.println(“java.version=” + System.getProperty(“java.version”));

Presentation presentation = new Presentation(“Aspose_15_test.pptx”);
ISlide slide1 = presentation.getSlides().get_Item(0);
for (int i = 0; i < slide1.getShapes().size(); i++) {
IShape shape = slide1.getShapes().get_Item(i);
if (shape.getName().equals(“MainTable”)) {
ITable table = (ITable)shape;
table.get_Item(0, 0).getTextFrame().setText(“Cell_0_0”);
table.get_Item(1, 1).getTextFrame().setText(“Cell_1_1”);
table.get_Item(2, 2).getTextFrame().setText(“Cell_2_2”);
table.get_Item(3, 3).getTextFrame().setText(“Cell_3_3”);
table.get_Item(4, 4).getTextFrame().setText(“Cell_4_4”);
table.get_Item(5, 5).getTextFrame().setText(“Cell_5_5”);
table.get_Item(6, 6).getTextFrame().setText(“Cell_6_6”);
}
}
presentation.save(“slides.pdf”, SaveFormat.Pdf);
System.out.println(new java.util.Date());

We have a license for Aspose.Total.

Hi Hasse,

Thanks for your interest in Aspose.Slides.

I have observed the sample code shared by you and like to share that you are setting the text on text frame level. When you do so, you are resetting the text to default formatting. In order to retain the text formatting, you need to set the text on portion level. Please visit this documentation link for your kind reference in this regard as well. I have shared the modified code sample for your reference as well.

Many Thanks,

The supplied code doesn’t fix the problem. I have attached the output I get. Don’t you get the same?

Hi Hasse,

I have observed the PDF. The issue is not related to Aspose.Slides. The cells for which there is no text in the cells there is no formatting information. If those cells have been filled with the the sample text with desired formatting like first and last cell, then they must have adhered to formatting. Since there is no formatting information for them, they are therefore rendered with default formatting. There are two possible solutions. The easier one is to fill all cells with some sample text by using desired formatting. When you will set the text for that portion, Aspose.Slides will adhere to source formatting. The other option is to copy the formatting of one of cells that is already added with your desired formatting (In your case its first and last cell) and set that for rest of portions where desired formatting information is unavailable. You can use Paragraph and portion copying mechanism in this regard to serve the purpose. Please visit this documentation link for your kind reference in this regard.

Many Thanks,

Thanks for the explanation but this is still not 100% correct. The first cell has both the new and the old text in it (should be cell_0_0 and not containing the 12). Please see the former attachment. This was not how it was before, but is this how it works from now on?

Hi Hasse,


I like to share that the cell_0_0 has three portions inside it. However, we are setting the text in first portion only. This is not issue with Aspose.Slides but a matter of how data is available in the cell. Actually, every text frame has collection of paragraphs. The paragraphs inside the text are define based on new line feeds or bullets. Every, paragraph has a collection of portions inside it. The text is divided in portions on the basis of formatting set in PowerPoint for the paragraph text. So, in your case when you look at text on text frame level, you will get TNR 12. When you dig down further and observe the text on paragraph level, you will still get TNR 12 as there is only one paragraph in the text frame of the cell. However, when you dig further down to portion level the text is divided into three portions, TNR 12 and " ". But we have replaced text in first portion only and that is why the 12 and " " is still there in your PDF. This is not issue with Aspose.Slides but your text formatting is changed for three different elements and thus resulting in three portions.

So, one option is to review your template and clear the text formatting of the cell and make entire cell follow the single formatting and it will have one single portion inside paragraph. The other option is to remove the rest of portions except first one. I have shared the modified sample code that actually removes the rest of portions from cell_0_0 to get the desired results.

public static void testTableText()
{
System.out.println(“os.name=” + System.getProperty(“os.name”));
System.out.println(“os.version=” + System.getProperty(“os.version”));
System.out.println(“java.version=” + System.getProperty(“java.version”));



Presentation presentation = new Presentation(path+“Aspose_15_test.pptx”);
presentation.joinPortionsWithSameFormatting();
ISlide slide1 = presentation.getSlides().get_Item(0);

for (int i = 0; i < slide1.getShapes().size(); i++) {
IShape shape = slide1.getShapes().get_Item(i);
if (shape.getName().equals(“MainTable”)) {
ITable table = (ITable)shape;

int portionCount=table.get_Item(0, 0).getTextFrame().getParagraphs().get_Item(0).getPortions().getCount();
if(portionCount>1)
for(int j=1;j<portionCount;j++)
table.get_Item(0, 0).getTextFrame().getParagraphs().get_Item(0).getPortions().removeAt(1);


table.get_Item(0, 0).getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).setText(“Cell_0_0”);


table.get_Item(1, 1).getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).setText(“Cell_1_1”);
table.get_Item(2, 2).getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).setText(“Cell_2_2”);
table.get_Item(3, 3).getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).setText(“Cell_3_3”);
table.get_Item(4, 4).getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).setText(“Cell_4_4”);
table.get_Item(5, 5).getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).setText(“Cell_5_5”);
table.get_Item(6, 6).getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).setText(“Cell_6_6”);
}
}


presentation.save(“slides.pdf”, SaveFormat.Pdf);
System.out.println(new java.util.Date());


}


Many Thanks,

Per your recommendation I have attached an example solution. Could you please have a look?

Hi Hasse,

I am sorry, I did not get your point. I have shared the sample code with you that is addressing the issue of 12 being displayed on cell_0_0. Is there some thing else that I may help you with. Can you please share is there any issue with sample code that you have shared in your last post. I also recommend you to please give a try to my sample code in my last post.

Many Thanks,