在 .NET Core 中使用 Syncfusion 创建 PDF 时使用 "custom" 字体

Using a "custom" font when creating a PDF with Syncfusion in .NET Core

我正在尝试使用 .NET Core 创建 PDF,我正在使用 Syncfusion 的 PDF 库来完成它。

根据他们的docs,我应该可以使用下面的代码:

PdfFont font = new PdfTrueTypeFont(new Font("Arial", 14));

然而,我仅有的 CTOR 是:

public PdfTrueTypeFont(Stream fontStream, float size);
public PdfTrueTypeFont(PdfTrueTypeFont prototype, float size);
public PdfTrueTypeFont(Stream fontStream, float size, PdfFontStyle style);

这些是我安装的 Syncfusion 包

"Syncfusion.Compression.Portable": "15.1120.0.37",
"Syncfusion.Pdf.Portable": "15.1120.0.37"

我也尝试了 MVC 版本,而不是 Portable 版本。

我正在使用最新的 .NET Core,"netstandard1.6"

我是不是遗漏了一个包,做错了什么,还是 .NET Core 还不支持它?

我的最终目标是能够使用 .NET Core 库中的任何网络安全字体 () 将文本写入 PDF。我还需要一种能够测量文本的方法。

由于PdfTrueTypeFont 不支持在.Net Core 中提供字体名称,您可以将.ttf 字体作为Stream 提供给PdfTrueTypeFont

string path = _hostingEnvironment.WebRootPath + "/Font/Arial.ttf";  

Stream fontStream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite);  

//Create a new PDF true type font.  
PdfTrueTypeFont tFont = new PdfTrueTypeFont(fontStream, 12,PdfFontStyle.Regular); 

PdfTrueTypeFontPdfStandardFont 的帮助下,我们创建了一个示例来绘制 PDF 中的文本。而且,使用变量来测量给定文本的大小。

请从下面找到样本link:
http://www.syncfusion.com/downloads/support/directtrac/174333/ze/sample-2079659962

有关 .Net Core 中支持的功能,请参阅以下内容link:
https://help.syncfusion.com/file-formats/pdf/supported-and-unsupported-features