Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using Docx dll to get paragraph information but not able to get paragraph format(font size-fontName-FontColor) Here is my code for that:


C#
using (DocX document = DocX.Load("Test.docx"))
{

    if (document.Paragraphs.Count() > 0)
    {

        for (int i = 0; i < document.Paragraphs.Count; i++)
        {
            Novacode.Paragraph pg = document.Paragraphs[i];
            Console.WriteLine("Text:" + pg.Text +" Alignment:" + pg.Alignment + " Direction:" + pg.Direction);
            //how get FontName-FontSize
        }
    }
}
Posted
Comments
Maciej Los 21-Nov-13 18:27pm    
If you use third-party dll, please provide an information about developer (link to site would be very appreciated).
Nobody can help you without necessary information.
Muhammad nasir 31-Jan-15 12:56pm    
i am solving the same problem too if you have a solution now can you share :P

1 solution

if a text is formatted you can access the formats via the MagicText property in the paragraph
C#
foreach (var mt in pg.MagicText)
{
  if (mt == null)
     continue;
  if (mt.formatting != null)
  {
  FontName = mt.formatting.FontFamily.Name.ToString();
 }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900