Skip to content

Commit 1c7d44b

Browse files
Merge pull request #2245 from syncfusion-content/1007100-ug
1007100-ug: Why Does PdfTrueTypeFont Fail to Load System Fonts Automatically
2 parents 742bece + cc3b110 commit 1c7d44b

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Document-Processing/PDF/PDF-Library/NET/Working-with-Text.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,6 +3149,40 @@ if (!searchText.Any(text => pageText.Contains(text)))
31493149
<br>
31503150
Create fonts, brushes, and pens once and reuse them throughout the document to reduce memory usage and improve rendering speed.
31513151

3152+
</td>
3153+
</tr>
3154+
</table>
3155+
3156+
### Why does `PdfTrueTypeFont` fail to load system fonts automatically?
3157+
3158+
<table>
3159+
<th style="font-size:14px" width="100px">Issue
3160+
</th>
3161+
<th style="font-size:14px">When you create a PdfTrueTypeFont using only a font family name (e.g., "Arial") in .NET Core or cross‑platform apps, the font can fail to load causing missing text, wrong rendering, or "font not found".
3162+
</th>
3163+
3164+
<tr>
3165+
<th style="font-size:14px" width="100px">Reason
3166+
</th>
3167+
<td><b>In .NET Framework</b>: the PDF library can resolve installed fonts by name <i>(e.g., new Font("Arial", 20) → new PdfTrueTypeFont(font, true) works)</i>.
3168+
<br>
3169+
<b>In .NET Core and cross‑platform environments</b>: system font APIs aren't exposed the same way, so PdfTrueTypeFont cannot locate fonts by name you must provide the actual <i>.ttf</i> file (path or stream) to load the font reliably.
3170+
</td>
3171+
</tr>
3172+
3173+
<tr>
3174+
<th style="font-size:14px" width="100px">Solution
3175+
</th>
3176+
<td>
3177+
Load the font directly from a <i>.ttf</i> file using a path or stream, then pass it to <a href="https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfTrueTypeFont.html">PdfTrueTypeFont</a>. This ensures consistent font embedding across all platforms.
3178+
{% tabs %}
3179+
{% highlight C# tabtitle="C#" %}
3180+
3181+
PdfTrueTypeFont ttf = new PdfTrueTypeFont("Arial.ttf", 20);
3182+
3183+
{% endhighlight %}
3184+
{% endtabs %}
3185+
31523186
</td>
31533187
</tr>
31543188
</table>

0 commit comments

Comments
 (0)