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

Free Support Forum - aspose.com

How to get pixel length of a string using C#


I am trying to remove answers from a test docx. The answers are underlined so we would like to remove the text above the underline for a 'student' test docx.

The problem is, if I just replace the text with blank spaces, the underline becomes much shorter.

How does one measure the pixel length of a string? System.Drawing.Graphics has a function called MeasureString which returns the string length in pixels based on the string and the font. Is there some equivalent in Aspose.Words? Can this be done?



Thanks for your inquiry. It would be great if you please share your input document along with expected output document here for our reference. We will investigate as to how you want your final Word output be generated like. We will then provide you more information on this along with code.

Following code example returns the bounding rectangle of the current entity relative to the page top left corner.

Document doc = new Document(MyDir + "in.docx");
LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
var renderObject = layoutCollector.GetEntity(para);
layoutEnumerator.Current = renderObject;
RectangleF location = layoutEnumerator.Rectangle;

A post was split to a new topic: Blank content of Run in output document