# Text Measuring

SpreadProcessing provides a built-in functionality and an extensibility point for text measuring to overcome the limitation of .NET Standard. Because the platform is intended to work on different devices, it does not expose a text measuring API. SpreadProcessing must have its own API to find out the letter and word sizes when exporting to PDF.

The following sections describe the default and the extended implementations used to measure text while exporting to PDF.

## Using a Text Measurer

The `SpreadExtensibilityManager` static class exposes the `TextMeasurer` property. This property defines the specific implementation that measures the text content when needed. You can use the following values for this property:

| Value                                                                                                                                                                                      | Description                                                                                                                                                                                                     |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`SimpleTextMeasurer`](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/cross-platform-support/text-measure#simpletextmeasurer)           | The default value. Provides basic text measuring using pre-measured digit widths.                                                                                                                               |
| [`SpreadFixedTextMeasurer`](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/cross-platform-support/text-measure#spreadfixedtextmeasurer) | An additional implementation that provides more accurate results than the `SimpleTextMeasurer`.                                                                                                                 |
| [`SkiaTextMeasurer`](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/cross-platform-support/text-measure#skiatextmeasurer)               | A cross-platform text measurer that supports advanced font features such as kerning, ligatures, and contextual shaping, with a trade-off in performance. Relies on the fonts registered on the current machine. |
| [Custom implementation](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/cross-platform-support/text-measure#custom-text-measurer)        | Implementing the abstract `SpreadTextMeasurerBase` class enables you to provide your own implementation for text measuring.                                                                                     |

## SimpleTextMeasurer

This is the measurer used by default when exporting to PDF.

The width of the columns in Excel is stored as a character count calculated based on the maximum width of the digits from 0 to 9 with the Normal Style of the document applied to them. `SimpleTextMeasurer` uses the measured width of the digits for a predefined set of font families to calculate the column width based on the length of the text multiplied by the calculated character size.

| Property       | Description                                                                                                                 |
| -------------- | --------------------------------------------------------------------------------------------------------------------------- |
| `TextMeasurer` | Gets or sets a `SpreadTextMeasurerBase` instance used to provide text measuring. The default value is `SimpleTextMeasurer`. |

> The `SimpleTextMeasurer` provides basic functionality for text measuring and the results might not be satisfying in each case. For better results, use [SpreadFixedTextMeasurer](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/cross-platform-support/text-measure#spreadfixedtextmeasurer).

## SpreadFixedTextMeasurer

This implementation uses PdfProcessing to obtain the size of the text and provides great precision. You need to explicitly set it to the `TextMeasurer` property of `SpreadExtensibilityManager`.

> note Due to the [Font Limitations](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/cross-platform/fonts) of the [PdfProcessing](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/overview) library in .NET Standard, you must provide a [FontsProvider implementation](https://www.telerik.com/document-processing-libraries/documentation/knowledge-base/pdfprocessing-implement-fontsprovider) as well.

> important To use the `SpreadFixedTextMeasurer` class, you must add a reference to **Telerik.Documents.Fixed**.

**Example 1: Set SpreadFixedTextMeasurer as the text measurer**

```C#
SpreadTextMeasurerBase fixedTextMeasurer = new SpreadFixedTextMeasurer();
SpreadExtensibilityManager.TextMeasurer = fixedTextMeasurer;
```

## SkiaTextMeasurer

| Minimum Version | Q3 2025 |
| --------------- | ------- |

The `SkiaTextMeasurer` is a cross-platform text measurer that provides consistent text layout behavior across all supported platforms. Unlike other available measurer implementations, it also supports advanced font features like *kerning*, *ligatures*, *contextual shaping*, and more. This implementation reduces the need for maintaining multiple text measurement implementations across different platforms.

### Required References

To use the `SkiaTextMeasurer` class, reference it in one of the following ways:

#### Using NuGet Packages (Recommended)

* **Telerik.Documents.TextMeasurer.Skia** - This package automatically includes all required dependencies

#### Using Assembly References

If you prefer to reference assemblies directly, you need:

| Assembly                                                                   | Description                                                                   |
| -------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| **Telerik.Documents.TextMeasurer.Skia.dll**                                | Main assembly containing the `SkiaTextMeasurer` class                         |
| **Telerik.Text.Skia.dll**                                                  | Required dependency of Telerik.Documents.TextMeasurer.Skia.                   |
| **SkiaSharp.HarfBuzz.dll** (version 8.3.1.2) (and all of its dependencies) | Required dependency of Telerik.Text.Skia.dll, along with all its dependencies |

**Example 2: Set SkiaTextMeasurer as the text measurer**

```C#
SpreadTextMeasurerBase skiaTextMeasurer = new SkiaTextMeasurer();
SpreadExtensibilityManager.TextMeasurer = skiaTextMeasurer;
```

## Custom Text Measurer

You can assign any `SpreadTextMeasurerBase` implementation to the `SpreadExtensibilityManager.TextMeasurer` property. Inherit the abstract `SpreadTextMeasurerBase` class, implement the required members, and set the new implementation to the `TextMeasurer` property.

**Example 3: Create a custom SpreadTextMeasurerBase implementation**

```C#
public class CustomTextMeasurer : SpreadTextMeasurerBase
{
    private static readonly double ratioX = 1.035;
    private static readonly double ratioY = 1;
    private static readonly double ratioBaseline = 1;

    private readonly SpreadTextMeasurerBase originalMeasurer;

    public CustomTextMeasurer(SpreadTextMeasurerBase originalMeasurer)
    {
        this.originalMeasurer = originalMeasurer;
    }

    public override TextMeasurementInfo MeasureText(TextProperties textProperties, FontProperties fontProperties)
    {
        TextMeasurementInfo info = originalMeasurer.MeasureText(textProperties, fontProperties);

        Size size = info.Size;
        TextMeasurementInfo custom = TextMeasurementInfo.Empty;
        custom.BaselineOffset = info.BaselineOffset * ratioBaseline;
        custom.Size = new Size(
            size.Width * ratioX,
            size.Height * ratioY);
         return custom;
    }

    public override TextMeasurementInfo MeasureTextWithWrapping(TextProperties textProperties, FontProperties fontProperties, double wrappingWidth)
    {
        TextMeasurementInfo info = originalMeasurer.MeasureText(textProperties, fontProperties);

        Size size = info.Size;
        TextMeasurementInfo custom = TextMeasurementInfo.Empty;
        custom.BaselineOffset = info.BaselineOffset * ratioBaseline;
        custom.Size = new Size(
            size.Width * ratioX,
            size.Height * ratioY);
        return custom;
    }
}
```

**Example 4: Register a custom text measurer implementation**

```C#
SpreadTextMeasurerBase originalMeasurer = new SpreadFixedTextMeasurer();
SpreadTextMeasurerBase customTextMeasurer = new CustomTextMeasurer(originalMeasurer);
SpreadExtensibilityManager.TextMeasurer = customTextMeasurer;
```

## See Also

* [How to Eliminate Formatting Issues when Exporting XLSX to PDF Format](https://www.telerik.com/document-processing-libraries/documentation/knowledge-base/exporting-xlsx-to-pdf-formatting-issues)
* [Cross-Platform Support](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/cross-platform-support/cross-platform)
* [Using XlsxFormatProvider](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/formats-and-conversion/import-and-export-to-excel-file-formats/xlsx/xlsxformatprovider)
* [Using PdfFormatProvider](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/formats-and-conversion/pdf/pdfformatprovider)
* [PdfProcessing Library Documentation](https://www.telerik.com/document-processing-libraries/documentation/libraries/radpdfprocessing/overview)
* [How to Measure Text in WordsProcessing .NET Framework](https://www.telerik.com/document-processing-libraries/documentation/knowledge-base/wordsprocessing-measure-text-netframework)
* [How to Measure Text in WordsProcessing .NET Standard](https://www.telerik.com/document-processing-libraries/documentation/knowledge-base/wordsprocessing-measure-text-netstandard)
