Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion libraries/radpdfprocessing/concepts/fonts.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ All fonts that are not included in the 14 standard ones must be **embedded** in

### Registering a Font

If you want to use a font that is not part of the standard ones, register it using the `RegisterFont()` method of the `FontRepository` static class. The method requires four parameters: `FontFamily`, `FontStyle`, and `FontWeight` objects describing the font, and a byte array containing the raw font data.
If you want to use a font that is not part of the standard ones, register it using the `RegisterFont()` method of the `FontsRepository` static class. The method requires four parameters: `FontFamily`, `FontStyle`, and `FontWeight` objects describing the font, and a byte array containing the raw font data.
Comment thread
YoanKar marked this conversation as resolved.

**Example 1** demonstrates how to use the `RegisterFont()` method.

Expand All @@ -121,6 +121,23 @@ If you want to use a font that is not part of the standard ones, register it usi

<snippet id='pdf-register-font-net-standard'/>

### Registering a Font from a Stream

Use the `RegisterFont()` overload that accepts a `Stream` to avoid loading an entire font file into a `byte[]`. The stream must be readable and seekable.

RadPdfProcessing starts reading at the stream's current position and reads font data lazily.

<snippet id='pdf-register-font-stream'/>

The example retains ownership of `fontStream` and disposes it after it no longer uses the registered font.

Use the `leaveOpen` parameter to control stream ownership:

* Set `true` to retain stream ownership. Keep stream open and usable while registered fonts are in use.
* Set `false` to transfer stream ownership to RadPdfProcessing. Do not use or dispose stream after registration.

>important `ClearRegisteredFonts()` clears the registered font cache. Font objects created before the call remain usable. The method buffers required data and closes library-owned streams.

### Creating a Font

>tip Each registered font can be obtained from the font repository as a `FontBase` object and applied to a [TextFragment]({%slug radpdfprocessing-model-textfragment%}) through its `Font` property.
Expand Down
15 changes: 14 additions & 1 deletion libraries/radpdfprocessing/cross-platform/fonts.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ You can find a detailed `FixedExtensibilityManager` and `FontsProvider` implemen

<snippet id='libraries-pdf-cross-platform-fonts-set-fontsprovider'/>

### Providing Font Streams

To provide fonts stored outside system font directories, override `FontsProviderBase.GetFontStream(FontProperties)`. The method must return a readable, seekable stream.

This approach lets RadPdfProcessing read font data lazily instead of requiring the provider to load the complete font into a `byte[]`.

<snippet id='libraries-pdf-cross-platform-fonts-providing-font-streams'/>

Override `GetFontData(FontProperties)` because it is abstract. Return `null` when the provider serves all fonts through `GetFontStream()`.

RadPdfProcessing owns the stream that `GetFontStream()` returns. Return a new stream for every request. Do not dispose the stream after returning it.

Providers that override only `GetFontData(FontProperties)` remain supported. The base `GetFontStream()` method creates a stream from the returned byte array.

## See Also

* [Standard Fonts]({%slug radpdfprocessing-concepts-fonts%})
Expand All @@ -56,4 +70,3 @@ You can find a detailed `FixedExtensibilityManager` and `FontsProvider` implemen
* [Validating Fonts when Using Telerik Document Processing]({%slug validating-fonts-pdf-document-processing%})
* [Preserving Original Bold, Italic and Regular Fonts When Exporting PDF Documents Using PdfProcessing in .NET Standard]({%slug pdfprocessing-prevent-font-conversion-embedding-fonts%})
* [Resolving Font Differences Between Client and Server-Side PDF Generation in Telerik Document Processing]({%slug consistent-pdf-font-formatting%})

2 changes: 1 addition & 1 deletion libraries/radpdfprocessing/model/textfragment.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The `TextFragment` class in [RadPdfProcessing]({%slug radpdfprocessing-overview%
|-----------------------|-------------------------------------------------------------------------------------------------|
| **Clone** (*Introduced in Q2 2025*) | Creates a deep copy of this document element. |

>note To use a font that is not part of the [standard fonts]({%slug radpdfprocessing-concepts-fonts%}#standard-fonts), register it with the [RegisterFont()]({%slug radpdfprocessing-concepts-fonts%}#registering-a-font) method of the `FontRepository` static class.
>note To use a font that is not part of the [standard fonts]({%slug radpdfprocessing-concepts-fonts%}#standard-fonts), register it with the [RegisterFont()]({%slug radpdfprocessing-concepts-fonts%}#registering-a-font) method of the `FontsRepository` static class.

>important In **.NET Standard/.NET (Target OS: None)** environments, fonts beyond the [14 standard ones]({%slug radpdfprocessing-concepts-fonts%}#standard-fonts) require a [FontsProvider implementation]({%slug pdfprocessing-implement-fontsprovider%}) to be resolved correctly.

Expand Down