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

Free Support Forum - aspose.com

Paragraph lines/word count


I need to get the paragraph lines and word count using Aspose. Using “BuiltInDocumentProperties”, I can get the document lines/word count. But, I need the same information for the paragraph.

Do you have any other method to get the paragraph line count? please suggest me.
Thank you very much!

Hi Harish,

Thanks for your inquiry. The Aspose.Words.Layout namespace provides classes that allow to access information such as on what page and where on a page particular document elements are positioned, when the document is formatted into pages.

Please check “DocumentLayoutHelper” example project in Aspose.Words for .NET examples repository at GitHub. Please use following code example to get the total number of lines in a paragraph and Words count.

Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "in.docx");
RenderedDocument layoutDoc = new RenderedDocument(doc);
foreach (Section sections in doc.Sections)
    foreach (Paragraph paragraph in sections.Body.Paragraphs)
        Console.WriteLine("Paragraph text : " + paragraph.ToString(SaveFormat.Text));
        Console.WriteLine("Paragraph lines : " + layoutDoc.GetLayoutEntitiesOfNode(paragraph).Count);
        Console.WriteLine("Words Count : " + paragraph.ToString(SaveFormat.Text).Split(' ').Length);

It’s working. Thanks for your help.

Hi Harish,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

I also got some need to measure the size of rendered span and “DocumentLayoutHelper” code helped me. But I got one issue it works fine on laptop but when I test same on desktop, it gives different width of rendered span.
Code I am using:

RenderedDocument layoutDoc = new RenderedDocument(doc);
var layout = layoutDoc.GetLayoutEntitiesOfNode(para);
layout[0].Spans[0].Rectangle.Width; //this width vary from desktop to laptop

Please help, give some clue.

Thanks for your inquiry. Please make sure that you are using the same document and code example. If you still face problem, please attach the following resources here for testing:

  • Your input Word document.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.
PS: To attach these resources, please zip and upload them.