Free Support Forum - aspose.com

Urgent - Weird fonts appearing on slides

Hi There,

Here is the story:

1. We are creating our presentation as we have done successfully in the past 2+ years.
2. In our latest version, we introduced a new step. We take the master slide from another PPT file ("template") and apply it on top of the presentation generated in step 1. We used your recommendation for implementing this step.
3. Recently, we have received complains that some users cannot read the text, because it appears in wingdings font!

Strangely, the same PPT file appears OK in our development environment. I have noticed that the font for text boxes is "times", which is not a valid name. I am guessing on our users' PC MS PowerPoint has difficulty interpreting "times" font and it defaults to wingdings.

Please open the attached .ppt file and activate any of the text boxes (e.g. Market Share Trend) and notice the font is "times". The second attachment is a screenshot taken by the user.

Any clue where "times" font came from? why wingdings font is selected for showing text?

I would REALLY appreciate it if you could treat this as a high priority issue.

Many thanks,

Fereshteh

Dear Fereshteh,

How did you create sample.ppt? If you created it with Aspose.Slides, then please provide the related source code and template presentation, so that we could find out how font named "times" came in sample.ppt.

It seems that required fonts are installed on your development environment but they are not installed on your client's machines.

It was created using Aspose.Slides. The source code is huge. I cannot share it with you. However, I can tell you how we apply the master template as the last step. Please find the code below. Imagine m_masterTemplate being the attached PPT file and m_show the main presentation.

// Clone an empty slide from m_masterTemplate to m_show.
// In this case master slide is also copied.

Slide clonedSlide = m_masterTemplate.CloneSlide(m_masterTemplate.GetSlideByPosition(1),

m_show.Slides.LastSlidePosition + 1, m_show, new System.Collections.SortedList());

// Now m_show contains 1 extra slide (cloned) + 1 logo master from m_masterTemplate.
// Replace master for m_show own slides and then
// delete the slide (not master) which was cloned from m_masterTemplate.

Slide logoMaster = m_show.GetSlideById(clonedSlide.MasterId);

foreach (Slide slide in m_show.Slides)
slide.ChangeMaster(logoMaster);

m_show.Slides.Remove(clonedSlide);

m_show.DeleteUnusedMasters();

You mentioned: "It seems that required fonts are installed on your development environment but they are not installed on your client's machines." Is there any way to specify a default font in presentations? Any workaround would be good at this point.

Thanks,

Fereshteh

If you will not set the font, then it will be by default Arial.

We do not set the default font during generation of the presenattion. Is this an MS PowerPoint setting?

I'd like to draw your attention to the piece of code that I have posted. I am positive fonts are messed up after that piece is executed.

Any thoughts?

Fereshteh

Dear Fereshteh,

By default font, I mean, if you simply set any of the TextFrame.Text, Paragraph.Text or Portion.Text property without specifying any font, then Aspose.Slides will take it Arial by default.

I can’t reproduce the bug regarding the invalid font namely “times”. The code below, first generate presentation namely m_show from scratch and then add a table with two rows and set text in each of the cell. Then it writes the presentation on disk with the name outShow.ppt, if you see it by opening, you will see that font is Arial

Moving onward, it changes the master of the m_show slides using the exact code provided by you except I modified your foreach loop and write the presentation with the name outShow2.ppt.

As you can see in outShow2.ppt, no invalid font name appeared, it is still Arial.

I have attached both the ppt files including source files namely NielsenTemplatePPT.ppt

***********************************************

string dirPath = @"D:\downloads\";

Presentation m_show = new Presentation();

Slide m_showSld = m_show.GetSlideByPosition(1);

//Add a table

Aspose.Slides.Table m_showTbl = m_showSld.Shapes.AddTable(500, 500, 5000, 1000, 1, 2);

//m_showTbl.SetBorders(0, Color.Black);

//Add a text in first cell

Aspose.Slides.Cell m_showTblCell = m_showTbl.GetCell(0, 0);

m_showTblCell.TextFrame.Text = "Is my market share growing or declining?";

//Add text in second cell

m_showTblCell = m_showTbl.GetCell(0, 1);

m_showTblCell.TextFrame.Text = "DOLLARS - PHILADELPHIA CENSUS TA - ALL PURPOSE BAKING MIX - 4 W/E 02-24-07";

//Write the presentation on disk to view

m_show.Write(@"c:\outShow.ppt" );

//Change its template

Presentation m_masterTemplate = new Presentation(dirPath + "NielsenTemplatePPT.ppt");

Slide clonedSlide = m_masterTemplate.CloneSlide(m_masterTemplate.GetSlideByPosition(1),

m_show.Slides.LastSlidePosition + 1, m_show, new System.Collections.SortedList());

// Now m_show contains 1 extra slide (cloned) + 1 logo master from m_masterTemplate.

// Replace master for m_show own slides and then

// delete the slide (not master) which was cloned from m_masterTemplate.

Slide logoMaster = m_show.GetSlideById(clonedSlide.MasterId);

for (int i = 1; i <= m_show.Slides.LastSlidePosition; i++)

{

Slide slide = m_show.GetSlideByPosition(i);

slide.ChangeMaster(logoMaster);

}

//foreach (Slide slide in m_show.Slides)

// slide.ChangeMaster(logoMaster);

m_show.Slides.Remove(clonedSlide);

m_show.DeleteUnusedMasters();

m_show.Write(@"c:\outShow2.ppt");

Thanks for the reply. Unfortunately, that does not resolve the problem.

Re: "I can’t reproduce the bug regarding the invalid font namely “times”", please see the attached screenshot. It should clarify the issue.

I'm hoping by learning about the "times" font, I could find some clues.

Thanks,

Fereshteh

The attached screenshot from the font dialog confirms that the issue stems from "times" font.

Any thoughts?

Thanks,

Fereshteh

I did further investigation and learnt something that I believe will lead me to a workaround (with your help):

I loaded NielsenTemplatePPT.ppt as an Aspose.Slides.Presentation and iterated through the Fonts collection. I found the collection consisting of 2 FontEntity objects.

1. Font Name = “Arial”

2. Font Name = “Times”.

Please see the attached screenshot.

The question is: “How can I modify NielsenTemplatePPT.ppt and remove the “Times” font?

Many thanks,

Fereshteh

Here is NielsenTemplatePPT.ppt for your review.

Load the presentation and change the font name to “Times New Roman”

It has to be done programmatically. I cannot ask the end users to make this change every time they produce a PPT output.

Please note that while generating the presentation, we specify the exact font for individual portions of each text box. The default font is set to "times" later when the master template is applied. Also, please note that in each textbox we often use more than one font (see the screenshot).

Repeating my question: “How can I modify NielsenTemplatePPT.ppt and remove the “Times” font?

Just to clarify:

How (using MS PowerPoint) can I modify NielsenTemplatePPT.ppt and remove the “Times” font?

Please note that while generating the presentation, we specify the exact font for individual portions of each text box. The default font is set to "times" later when the master template is applied

Can you show me your code for the above; probably you are missing something there?

It seems, you have not generated this NielsenTemplatePPT.ppt using PowerPoint, probably, you had generated it using Aspose.Slides and accidentally added a wrong font name inside it. As far as I know, you can not add fonts or remove using PowerPoint.

As an example, I have created a ppt file with wrong font name using the code below, which is attached, along with the jpg image showing the wrong font.

One more thing that I could think of is that PowerPoint shows the names of the fonts currently installed on the machine and probably a font named “Times” was installed on a machine in which it was created initially and creator of this presentation set this font and now it is moving along with this ppt.

*******************************************

SettingLicense();

Presentation srcPres = new Presentation();

FontEntity fnt = new FontEntity(srcPres, srcPres.Fonts[0]);

fnt.FontName = "Dummy Font";

srcPres.Write("c:\\outDummyFont.ppt");

Could you please tell me how we can set the default font for a Paragraph/TextFrame object (programmatically)? We set the font for individual Portion objects, but the TextFrame/Paragraph itself doesn't have a specific font set. I am confident that the undefined font for the TextFrame is causing the problem in our case.

Thanks,

Fereshteh

Please see this thread to see, how to add new fonts and change the existing one.

http://www.aspose.com/Community/Forums/thread/92777.aspx

You just need to add a new font name in Presentation.Fonts collection, note its index and then change the TextFrame.Paragraphs[paraIdx].Portions[portIdx].FontIndex property with that index.

I'm afraid you didn't get my question. I know how to set the font for individual Portions of a Paragraph. I need to find a way to set the default font for the TextFrame that owns the Paragraph.

Fereshteh

When you create a presentation like this

Presentation pres=new Presentation();

Initially, the Presentation.Fonts collection contains only font at index 0 namely Arial. All rest fonts are added later by programmer.

For example, if we add a Times New Roman later, then it will be added at index 1 of Presentation.Fonts collection.

Now, if you change the TextFrame.Paragraphs[paraIdx].Portions[portIdx].Font=0; text will be in Arial, but if you set it 1, then text will be in Times New Roman.

Now, if you want to set the default font, then you need to first define which font you want to take as default, add it in Presentation.Fonts collection and note its index and then iterate all the TextFrames and TextHolders and set Portion.FontIndex property of all the portion objections inside them to your default font index.

I hope it is clarified. In short, there is no default font, it is the programmer’s responsibility to add some font as default and set every Portion.FontIndex accordingly.

However, if the presentation is created by Aspose.Slides, then you can safely assume that setting Portion.FontIndex=0 will make the text in Arial.