Measure from text word

By using Spire.Doc, developers can find and highlight the text, extract the text in word document. This article will show you how to get the height and width of text in a word document in C# with the help of Spire.Doc.

Firstly, Download and install Spire.Doc for .NET and then add Spire.Doc.dll as reference in the downloaded Bin folder though the below path: «..Spire.DocBinNET4.0 Spire.Doc.dll». Here comes to the details of how to get the height and width of text in a word document in C#.

Check the original word document at first:

How to get the height and width of text in word document in C#

Step 1: Create a new document and load from file.

Document doc = new Document();
doc.LoadFromFile("Word.doc");

Step 2: Define the text string that we need to get the height and width.

string text = "Microsoft Word is a word processor designed by Microsoft.";

Step 3: Get the text string and measure the string.

//finds and returns the string with formatting
TextSelection selection = doc.FindString(text, true, true);
//get the font
Font font = selection.GetAsOneRange().CharacterFormat.Font;
//initialize graphics object
Image fakeImage = new Bitmap(1, 1);
Graphics graphics = Graphics.FromImage(fakeImage);
//measure string
SizeF size = graphics.MeasureString(text, font);

Step 4: Get the text height and width and read it.

Console.WriteLine("text height:{0}",size.Height);
Console.WriteLine("text width:{0}", size.Width);
Console.ReadLine();

Effective screenshot:

How to get the height and width of text in word document in C#

Full codes:

using Spire.Doc;
using Spire.Doc.Documents;
using System;
using System.Drawing;
namespace GetHeightandWidth
{

    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("Word.doc");
            string text = "Microsoft Word is a word processor designed by Microsoft.";

            TextSelection selection = doc.FindString(text, true, true);
            Font font = selection.GetAsOneRange().CharacterFormat.Font;
            Image fakeImage = new Bitmap(1, 1);
            Graphics graphics = Graphics.FromImage(fakeImage);
            SizeF size = graphics.MeasureString(text, font);

            Console.WriteLine("text height:{0}", size.Height);
            Console.WriteLine("text width:{0}", size.Width);
            Console.ReadLine();
        }
    }
}

When setting indents or tabs on the ruler in Microsoft Word, you can see approximate measurements using the markings on the ruler. However, if you need more detailed measurements, there is an easy way to get this information.

The markings on the ruler can show you how far in from the left an indent or a tab is, but maybe you need to know how far from the right side it is. Word has a handy, little-known feature that will show you the exact measurements as you move indents or tabs on the ruler.

First, you need to make sure the ruler is showing. If you don’t see the ruler at the top of the document, click the “View” tab.

Then, check the “Ruler” box in the Show section of the View tab.

You can see measurements when moving margins (or indents) and tabs. The indent markers are the triangles and the square below them on the left side of the ruler. The top triangle is for the first line indent (only the first line of a paragraph is indented), the bottom triangle is for the hanging indent (all lines but the first one in a paragraph are indented), and the box below the two triangles is for the left indent (all lines in a paragraph are indented).

Say you want to move the left indent over to 0.86 inches on the ruler. Click and hold the left mouse button on the box below the two triangles on the left side of the ruler. Then, click and hold the right mouse button (while still holding down the left button) and move the mouse to the right. You’ll notice measurements displaying where the ruler was. The measurement to the left of the indent marker is the left indent and what you want to be 0.86 inches. The measurement to the right of the indent marker is the width of the paragraph. Release the mouse buttons when you get to the measurement you want.

You can also move the triangle on the right side of the ruler (the right margin) the same way, viewing the measurements as you move the mouse with both buttons pressed down.

The measurement in gray on the left is the margin size set on the Layout tab. The margin size can also be changed here If you move your mouse to the left while both buttons are pressed.

Tabs can be moved the same way. Place a tab on the ruler and then click and hold with the left mouse button and then the right button and move the mouse. You’ll see measurements display and you can move the tab to an exact location.

The measurements display in whichever unit of measurement you have selected in Word.

READ NEXT

  • › How to Indent Paragraphs in Google Docs
  • › BLUETTI Slashed Hundreds off Its Best Power Stations for Easter Sale
  • › How to Adjust and Change Discord Fonts
  • › Google Chrome Is Getting Faster
  • › HoloLens Now Has Windows 11 and Incredible 3D Ink Features
  • › The New NVIDIA GeForce RTX 4070 Is Like an RTX 3080 for $599
  • › This New Google TV Streaming Device Costs Just $20

How-To Geek is where you turn when you want experts to explain technology. Since we launched in 2006, our articles have been read billions of times. Want to know more?

В понедельник, 22 февраля, стало известно, что Microsoft собирается внедрить в Word функцию предсказания текста. По данным Neowin, обновление станет доступным для всех пользователей уже в следующем месяце.

Напомним, что компания Microsoft рассказала о разработке этой функции еще в 2020 году. Вскоре после публикации новости опция стала доступной примерно половине пользователей канала для тестирования апдейтов.

Предсказание текста работает на основе машинного обучения. Система анализирует текст, вводимый пользователем в редакторе, и предлагает свои варианты слов. Подсказки окрашиваются в серый цвет. Чтобы применить их в тексте пользователю необходимо всего лишь нажать на клавишу Tab. Чтобы отклонить ввод подсказки, достаточно нажать на Escape. В Microsoft обещают, что новая функция будет предсказывать текст быстро и точно. Благодаря этому пользователь сможет повысить производительность времени, проведенного в текстовом редакторе.

Немаловажно, что качество предсказания текста со временем улучшается. Это связано с тем, что система машинного обучения будет анализировать стиль письма пользователя. При этом никакие аналитические данные о текстах не будут передаваться третьим лицам.

Разработчики предусмотрели опцию полного отключения новой функции для тех, кого она отвлекает от работы. В Microsoft отметили, что хотят получить отзывы от пользователей об удобстве работы с подсказками текста. Их вместе с жалобами и пожеланиями можно отправлять через механизм Feedback в Word (в меню Help).

Отметим, что Microsoft Word — это не первый компонент пакета Office с функцией прогнозирования текста. Ранее в этом месяце поддержка опции появилась в Outlook.

  • Забавные случаи, когда компании троллили друг друга. Чаще доставалось Apple
  • 10 малоизвестных функций Word, которые вы зря не используете. Продуктивность возрастает в разы
  • Браузерный «офис» от Яндекса, Google или Microsoft: детальное сравнение сервисов
  • Российские Р7-Офис и МойОфис против Word и Excel: сравнение в функциях и производительности
  • Как сделать кроссворд в Word: это проще, чем кажется

Please Note:
This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Changing Measurement Units.

Written by Allen Wyatt (last updated February 9, 2019)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


Word allows you to modify your work environment extensively. One of the changes you can make involves the default units of measurement used in dialog boxes and on the ruler. By default, Word uses inches, but you can customize the program so it will use centimeters, picas, points, or millimeters.

To change the default measurement units, follow these steps:

  1. Display the Word Options dialog box. (In Word 2007 click the Office button and then click Word Options. In Word 2010 or a later version display the File tab of the ribbon and then click Options.)
  2. Click Advanced at the left side of the dialog box.
  3. Scroll through the available options until you see the Display section. (See Figure 1.)
  4. Figure 1. The Display section of the Advanced options in the Word Options dialog box.

  5. Using the Show Measurements in Units Of drop-down list, select the units of measurement you want used by default.
  6. Click on OK.

WordTips is your source for cost-effective Microsoft Word training.
(Microsoft Word is the most popular word processing software in the world.)
This tip (6698) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Changing Measurement Units.

Author Bio

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. Learn more about Allen…

MORE FROM ALLEN

Unwanted Graph Paper Effect

When you open a document or start to use Word, do you see a background that looks like graph paper? It could be because …

Discover More

Determining Your Version of Excel

Want to find out exactly what version of Excel you are using? Here’s how to get to the info.

Discover More

Removing a Directory

Your macro, in the course of doing some processing, may create a directory that you later need to delete. Here’s how to …

Discover More

More WordTips (ribbon)

Turning Off the Automatic Help that Word Offers

Word has a lot of tools that are invoked automatically based on what you are doing in the program. If these tools …

Discover More

Showing Text Boundaries for Pages, not for Paragraphs

Word allows you to configure how your document is displayed rather extensively. One configuration that has been around …

Discover More

Getting Rid of Blue Squiggly Underlines

In an effort to make your writing better, Word uses «squiggly» underlines to mark things it thinks you may need to …

Discover More

Set the margin unit of measurement to inches, centimeters, millimeters, points, or picas.

Note: This change also affects the ruler and other measurements.

WindowsmacOS

  1. Go to File > OptionsAdvanced.

    Scroll down to Display.

  2. Select the unit you want in Show measurements in units of.

  3. Select OK.

  1. Go to Word > Preferences, and then under Authoring and Proofing Tools, select General.

  2. Select the unit you want in Show measurements in units of.

  3. Select OK.

Понравилась статья? Поделить с друзьями:
  • Meaning of word secret
  • Measure a line in word
  • Meaning of word saturday
  • Meaning of word satisfied
  • Means of travelling listen to the recording and type the correct word into the gap