使用 MigraDoc 在 Xamarin Forms 上创建 PDF 时找不到合适的字体
我正在尝试使用 MigraDoc 创建 pdf。以下是我正在使用的库的列表:
- MigraDoc.DocumentObjectModel
- MigraDoc.DocumentObjectModel.Tables
- MigraDoc.Rendering
它在 printer.RenderDocument()
上引发错误。下面的代码
private async Task SavePDF()
{
filePath = emulatorFolderPath + "/Signed/" + _reportInformationViewModel.SelectedClient.Username + "-" + DateTime.Now.ToString("dd_MM_yyyy HH-mm") + ".pdf";
MigraDocRendering.PdfDocumentRenderer printer = new MigraDocRendering.PdfDocumentRenderer
{
Document = document
};
printer.RenderDocument();
printer.PdfDocument.Save(filePath);
}
PS:我不需要使用私有字体。
I'm trying to create a pdf using MigraDoc. Here's a list of the libraries that I'm using:
- MigraDoc.DocumentObjectModel
- MigraDoc.DocumentObjectModel.Tables
- MigraDoc.Rendering
It throws me an error on printer.RenderDocument()
. Code below
private async Task SavePDF()
{
filePath = emulatorFolderPath + "/Signed/" + _reportInformationViewModel.SelectedClient.Username + "-" + DateTime.Now.ToString("dd_MM_yyyy HH-mm") + ".pdf";
MigraDocRendering.PdfDocumentRenderer printer = new MigraDocRendering.PdfDocumentRenderer
{
Document = document
};
printer.RenderDocument();
printer.PdfDocument.Save(filePath);
}
PS: I don't need to use a private font.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经通过实施
IFontResolver
解决了我添加了一个包含 Open-Sans 字体的文件夹
Fonts
。我创建了一个文件夹
Helpers
,其中包含一个名为GenericFontResolver
的类:然后,在需要我添加的字体的类的构造函数上:
GlobalFontSettings。 FontResolver = new GenericFontResolver();
然后,当我创建表时,您必须添加:
I've resolved by implementing
IFontResolver
I've added a folder
Fonts
that contains Open-Sans font.I've created a folder
Helpers
that contains a class calledGenericFontResolver
:Then, on the constructor of the class that needs the font I've added:
GlobalFontSettings.FontResolver = new GenericFontResolver();
Then, when I'm creating the table you must add: