How to get the specified paragraph's lines count

how to get the specified paragraph’s lines count?

Hi there,

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 read about Aspose.Words.Layout namespace from here:

https://reference.aspose.com/words/net/aspose.words.layout//

In your case, I suggest you please use DocumentLayoutHelper code example to achieve your requirements. Please check “DocumentLayoutHelper” example project in Aspose.Words for .NET examples repository at GitHub.

Please use the following code example to get the total number of lines of paragraphs. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");

RenderedDocument layoutDoc = new RenderedDocument(doc);

// Loop through each page in the document and print how many lines appear on each page.

foreach (RenderedPage page in layoutDoc.Pages)

{

LayoutCollection<LayoutEntity> lines = page.GetChildEntities(LayoutEntityType.Line, true);

Console.WriteLine("Page {0} has {1} lines.", page.PageIndex, lines.Count);

}

foreach (Paragraph paragraph in doc.GetChildNodes(NodeType.Paragraph, true))

{

Console.WriteLine("Paragraph text: " + paragraph.ToString(SaveFormat.Text));

Console.WriteLine("Paragraph lines : " + layoutDoc.GetLayoutEntitiesOfNode(paragraph).Count);

}

Console.ReadLine();

Thanks for your reply. That’s good.

Hi there,

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

Hello there,

Thank you for providing this source code. I am trying to use the RenderedDocument class, but it keeps telling me “are you missing an assembly or reference?” I have Aspose.Words installed, and am using it. Do you know what namespace this class falls under so I can use this?

Thanks,

@Tdprice51

Thanks for your inquiry. The RenderedDocument class is not part of Aspose.Words APIs. Please get the RenderedDocument class in Aspose.Words for .NET examples repository at GitHub.