We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Weird text formatting changes in Presentation

I have a method in one of my applications that substitutes portions of the text withing TextFrame and TextHolder with data from the database. The substitution works fine but when the slide is output as PPT (PP2003) color, size and weight of the text is different from the original template. I am not changing any proprty of the text formatting in the code and cannot figure out what is the cause of the issue. A portion of the code that performs substitution is attached below:

Presentation pres = LoadPresentationTemplate(Server.MapPath("."+"\\Strategy_Review_Template_Full Version_Updated for Testing.ppt"));

Slides slideCollection = pres.Slides;

foreach (Slide currentSlide in slideCollection)
{
if (currentSlide.Placeholders != null && currentSlide.Placeholders.Count > 0)
{
foreach (Placeholder p in currentSlide.Placeholders)
{
TextHolder th = p as TextHolder;
if (th != null)
{
//search paragraph text attribute and replace occurances of

  • with respected Data Values
    foreach (Paragraph par in th.Paragraphs)
    {
    par.Text = ReplaceTokens(par.Text, fieldMap);
    }
    }
    }
    }
    else if (currentSlide.Shapes.Count != 0)
    {
    foreach (Shape shape in currentSlide.Shapes)
    {
    if (shape.TextFrame != null)
    {
    foreach (Paragraph par in shape.TextFrame.Paragraphs)
    {
    par.Text = ReplaceTokens(par.Text, fieldMap);
    }
    }
    }
    }
    }

    //Method that performs replacement
    private string ReplaceTokens(string source, PowerPointMap fieldMap)
    {
    //string retVal = string.Empty;
    Regex rex = new Regex(@"\

  • [[a-zA-z0-9]+\]",RegexOptions.IgnoreCase | RegexOptions.Compiled);
    MatchCollection results = rex.Matches(source);
    foreach(Match match in results)
    {
    string token = match.Value;
    int index = fieldMap.Fields.BinarySearch(0, fieldMap.Fields.Count, token.Substring(1, token.Length - 2), (IComparer)new PowerPointMapElement.PowerPointMapElementComparer());
    if(index >=0)
    {
    source=source.Replace(token,((PowerPointMapElement)fieldMap.Fields[index]).DataValue);
    }
    }
    return source;
    }

    Please advise.

    Thanks

    Dear Leonid,

    Thanks for considering Aspose.

    Each Paragraph object has a Portion object collections. Portion is the actual object that holds formatting, so you should change the Paragraph.Text property to Portion.Text property.

    For example, in your code, you will replace

    par.Text = ReplaceTokens(par.Text, fieldMap);

    to

    par.Portions[0].Text = ReplaceTokens(par.Text, fieldMap);