Free Support Forum - aspose.com

Problem with font size of text in nested unordered listing

Hi there,

I am creating a slide using Aspose.Slides.dll of version 15.4.0.0. In nested unordered listing, I am having an UL within an UL. The problem is, font size of contents of Inner UL does not come same as the outer UL content,

Current output:
Capita was formed in 1984 within the Chartered Institute of Public Finance and Accountancy.
The company is headquartered in London, UK, and is listed on the London Stock Exchange.
It provides customer and business process management services to organisations in industries such as healthcare, property services, general insurance, investor and banking, services, integrated services, IT services and consulting.
The company’s business segments are as follows:
Health & Wellbeing
IT Services
Justice & Secure Services
Professional Services
Professional Services
Professional Services
Professional Services
Professional Services

Desired Output:

Font size of contents of nested UL/ Inner UL should be same as Outer UL content.

Please help. Please see below my code, Please find attached template file and generated pptx as well.

Code:
CreateUnorderedListing();

protected void CreateUnorderedListing()
{
string template = ConfigurationManager.AppSettings["TemplateFilePath"];
Presentation pres = new Presentation(MapPath(".") + "\\Templates\\PPTXTemplate.pptx");

ISlide sld = pres.Slides[pres.Slides.Count - 1];
IAutoShape iShapeBody = null;

//Iterate through shapes to find the placeholder
foreach (IShape shp in sld.Shapes)
{
if (shp.Placeholder != null)
{
if (shp is IAutoShape )
{
iShapeBody = (IAutoShape)shp;
}
}
}

string richText = "
  • Capita was formed in 1984 within the Chartered Institute of Public Finance and Accountancy.
  • The company is headquartered in London, UK, and is listed on the London Stock Exchange.
  • It provides customer and business process management services to organisations in industries such as healthcare, property services, general insurance, investor and banking, services, integrated services, IT services and consulting.
  • The company’s business segments are as follows:
    • Health & Wellbeing
    • IT Services
    • Justice & Secure Services
    • Professional Services
    • Professional Services
    • Professional Services
    • Professional Services
    • Professional Services
    • Professional Services
";

this.ParseHtmlContent(richText, iShapeBody);

pres.Save(System.Web.HttpContext.Current.Server.MapPath(template) + "SamplePPTReport123.pptx", SaveFormat.Pptx);
}

private ITextFrame txtFrame = null;
private IParagraph para = null;
private IPortion portion = null;
private bool isFirstNodeUlOl = false;
float yCoordinateValue = default(float);
float verticalGap = 10;

public IAutoShape ParseHtmlContent(string content, IAutoShape shape)
{
Presentation pres = (Presentation)shape.Presentation;
ILayoutSlide lsTitleWithContent = ((ISlide)shape.Slide).LayoutSlide;
// ISlide currentSlide = null;

try
{
yCoordinateValue = shape.Y;
para = null;
txtFrame = shape.TextFrame;
txtFrame.TextFrameFormat.AutofitType = TextAutofitType.Shape;

if (txtFrame != null)
{
if (txtFrame.Text.Contains("Text"))
{
//Removing the default exisiting paragraph
txtFrame.Paragraphs.RemoveAt(0);
}

para = new Paragraph();
txtFrame.Paragraphs.Add(para);
para.Portions.Add(new Portion());
portion = para.Portions[0];
}

HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.LoadHtml(content);

if (htmlDoc.DocumentNode.ChildNodes.Count > 0)
{
HtmlNode firstNode = htmlDoc.DocumentNode.ChildNodes[0];

if (firstNode.Name == "ol" || firstNode.Name == "ul")
{
isFirstNodeUlOl = true; // This is used to avoid adding new paragraph for first li when respective ul/ol is the first element in the shape.
}
}

foreach (HtmlNode node in htmlDoc.DocumentNode.ChildNodes)
{
shape = this.TraverseChildNodes(node, shape);

if (yCoordinateValue <= (shape.Y + shape.Height))
{
yCoordinateValue = shape.Y + shape.Height;
}
else
{
yCoordinateValue += verticalGap;

if (node.NextSibling == null)
{
yCoordinateValue += shape.Height;
}
}
}
}
catch (Exception ex)
{}

return shape;
}

public IAutoShape TraverseChildNodes(HtmlNode node, IAutoShape shape)
{
try
{
shape = this.ProcessNode(node, shape);

foreach (HtmlNode chldNode in node.ChildNodes)
{
TraverseChildNodes(chldNode, shape);
}
}
catch (Exception ex)
{}

return shape;
}

private IAutoShape ProcessNode(HtmlNode node, IAutoShape shape)
{
try
{
//This is for plain text after any ul/ol
if (node.PreviousSibling != null && (node.PreviousSibling.Name == "ul" || node.PreviousSibling.Name == "ol") && node.Name != "li" && node.Name != "p" && node.Name != "br")
{
if (txtFrame != null)
{
para = new Paragraph();
txtFrame.Paragraphs.Add(para);
para.Portions.Add(new Portion());
portion = para.Portions[0];
}
}

if (node.Name == "#text")
{
if (para != null && portion == null)
{
portion = new Portion();
para.Portions.Add(portion);
}

//handle bold, italic and underline tags for each text node. This also handles the nested tags
HtmlNode parentNode = node.ParentNode;

while (parentNode != null)
{
if (parentNode.Name == "b" || parentNode.Name == "strong")
portion.PortionFormat.FontBold = NullableBool.True;
else if (parentNode.Name == "i")
portion.PortionFormat.FontItalic = NullableBool.True;
else if (parentNode.Name == "u")
portion.PortionFormat.FontUnderline = TextUnderlineType.Single;

parentNode = parentNode.ParentNode;
}

StringBuilder textBuilder = new StringBuilder(node.InnerText);
textBuilder = textBuilder.Replace("[gt]", ">");
textBuilder = textBuilder.Replace("[lt]", "<");
textBuilder = textBuilder.Replace("[quot]", """);
textBuilder = textBuilder.Replace("[lsquo]", "‘");
textBuilder = textBuilder.Replace("[rsquo]", "’");
textBuilder = textBuilder.Replace("[ldquo]", "“");
textBuilder = textBuilder.Replace("[rdquo]", "”");
textBuilder = textBuilder.Replace("[apos]", "'");
textBuilder = textBuilder.Replace("[amp]", "&");

portion.Text = WebUtility.HtmlDecode(textBuilder.ToString());

portion = null;
//cell = null;
}
else if (node.Name == "p")
{
// para = null;

if (txtFrame != null)
{
if (!(txtFrame.Paragraphs.Count == 1 && txtFrame.Paragraphs[0].Text == string.Empty))
{

txtFrame.Paragraphs.Add(new Paragraph());
para = txtFrame.Paragraphs[txtFrame.Paragraphs.Count - 1];

para.Portions.Add(new Portion());
portion = para.Portions[0];
}
}
}
else if (node.Name == "br")
{
//para = null;

if (txtFrame != null)
{
txtFrame.Paragraphs.Add(new Paragraph());
para = txtFrame.Paragraphs[txtFrame.Paragraphs.Count - 1];

para.Portions.Add(new Portion());
portion = para.Portions[0];
}
}
else if (node.Name == "h1" || node.Name == "h2" || node.Name == "h3" || node.Name == "h4")
{
}
else if (node.Name == "li")
{
//Avoid adding new paragraph for first li when respective ul/ol is the first element in the shape
if (!isFirstNodeUlOl)
{
//Every list item needs to be new paragraph
para = new Paragraph();

if (txtFrame != null)
{
if (txtFrame.Text.Contains("Text"))
{
//Removing the default exisiting paragraph
txtFrame.Paragraphs.RemoveAt(0);
}

txtFrame.Paragraphs.Add(para);
para.Portions.Add(new Portion());
portion = para.Portions[0];
}
}

if (node.ParentNode.Name == "ul")
{
para.ParagraphFormat.Bullet.Type = BulletType.Symbol;
para.ParagraphFormat.Bullet.Height = 100;
para.ParagraphFormat.Alignment = TextAlignment.Left;
para.ParagraphFormat.Indent = 20;
}
else if (node.ParentNode.Name == "ol")
{
para.ParagraphFormat.Bullet.Type = BulletType.Numbered;
para.ParagraphFormat.Bullet.NumberedBulletStyle = NumberedBulletStyle.BulletArabicPeriod;
para.ParagraphFormat.Bullet.NumberedBulletStartWith = 1;
para.ParagraphFormat.Bullet.Height = 100;

para.ParagraphFormat.Alignment = TextAlignment.Left;
}

//finding the list indent level for each list item
short indentLevel = 0;
HtmlNode tempNode = node;

do
{
tempNode = tempNode.ParentNode;
if (tempNode.Name == "ul" || tempNode.Name == "ol")
indentLevel++;
} while (tempNode != null && (tempNode.Name == "ul" || tempNode.Name == "ol" || tempNode.Name == "li"));

para.ParagraphFormat.Depth = --indentLevel;

isFirstNodeUlOl = false;
}
}
catch (Exception ex)
{
//logger.Error(ex);
HttpContext.Current.Session["Error"] = "Error occured while parsing rich text || " + ex.Message;

throw ex;
}

return shape;
}

Hi Kavita,

I have observed the post shared by you and have observed the issue shared in presentation. I request you to please share the working sample project with us that is reproducing the issue on your end. I will use the sample project on my end to verify and help you further in this regard.

More importantly, if you are getting different font for different indentation level, I suggest you to please set the font on portion level explicitly. This is not issue with Aspose.Slides and the fonts settings for first, second and next levels set in your template master. There are two solutions for this. First is that you need to set the font explicitly for every portion in your code. The other option is set the fonts in your template presentation on master level. I hope the solution will be workable on your end.

Many Thanks,