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
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(@"\
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