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

Free Support Forum - aspose.com

How to get the valid text in a HTML document alone and display it in the PPTX portions

**Any quick response would be more than helpful **


What I want to achieve::
The purpose is to apply the styles applied to the html text into the pptx slide as paragraphs.

What I am Doing::
I am trying to load the html text into an html document and filter only the text nodes containing text values. Similarly, I am getting a reference to the paragraphs (which is supposed to be the paragraphs that is there in the html document) in the slide. I am comparing each html text node with the paragraph.portions in the slide and applying the styles as is in the html node to the portion.

But the problem is when the html document is loaded &nbsp, single space, \n\t are considered as the text node and the no.of child nodes for an element say "p" is not same as the portions in a paragraph returned by the slide. This results in improper styles applied to various portions of the slides.

Is there any other way to achieve this apart from . I want to apply the styles from the html node to my portions in PPTX slide.

Below is the code that I am working with.

protected override void Export(ISlide slide, int currentSlideIndex)
var frameShape = AddShapeUtils.AddHtmlFrame(slide, Data.Text, X, Y, Width, Height);

HtmlDocument htmlDoc = new HtmlDocument();

var htmlParagraphs = htmlDoc.DocumentNode.ChildNodes.Where(x => !x.Name.Contains("#text"));
var paragraphs = ((IAutoShape)frameShape).

Color defaultFgColor = DesignSettings.GetValueOrDefault("@UISetting-OnScreenReport-Text-Font-Color").GetColor();
FontData defaultFontType =
new FontData(DesignSettings.GetValueOrDefault("@UISetting-OnScreenReport-Text-Font-Family").Split(',')[0]);

for (int i = 0; i < paragraphs.Count; i++)
counter = 0;

VisitNode(htmlParagraphs.ElementAt(i), paragraphs[i].Portions, Color.White, defaultFgColor, defaultFontType, 13, DesignSettings);

TextFrame.TextFrameFormat.AutofitType = TextAutofitType.Normal;

private int counter = 0;

public void VisitNode(HtmlNode node, IPortionCollection portions, Color backgroundColor, Color foregroundColor, FontData fontType, float fontSize, Dictionary designSettings)
string bg = "background-color:";
string fg = "color:";
string font = "font-family:";
string fs = "font-size:";

if (node.HasAttributes && node.Attributes.Contains("style") && node.Attributes["style"].Value.IndexOf(bg) != -1)
backgroundColor = node.Attributes["style"].Value.Substring(bg.Length).GetColor();

if (node.HasAttributes && node.Attributes.Contains("style") && node.Attributes["style"].Value.IndexOf(fg) == 0)
foregroundColor = node.Attributes["style"].Value.Substring(fg.Length).GetColor();

if (node.HasAttributes && node.Attributes.Contains("style") && node.Attributes["style"].Value.IndexOf(font) != -1)
var titleFontsArray = node.Attributes["style"].Value.Substring(font.Length).Split(',');
fontType = new FontData(titleFontsArray[0]);

if (node.HasAttributes && node.Attributes.Contains("style") && node.Attributes["style"].Value.IndexOf(fs) != -1)
string s = node.Attributes["style"].Value;
fontSize = s.Substring(fs.Length, s.Length - fs.Length - 2).GetFontSize();
if (node.Name == "#text")
portions[counter].PortionFormat.FillFormat.FillType = FillType.Solid;
portions[counter].PortionFormat.FillFormat.SolidFillColor.Color = foregroundColor;
portions[counter].PortionFormat.LatinFont = fontType;
portions[counter].PortionFormat.FontHeight = fontSize;
portions[counter++].PortionFormat.HighlightColor.Color = backgroundColor;

foreach (HtmlNode childNode in node.ChildNodes)
VisitNode(childNode, portions, backgroundColor,foregroundColor, fontType, fontSize, designSettings);


Hi Priya,

Thank you for the details.

However, I am not very clear about your requirement.It seems from the details shared by you that you are facing some issue in parsing the HTML content. Please share a sample application, template files and the detail of the issue your are facing with Aspose.Slides API. We will check it and get back to you soon.

Thanks & Regards,