简体   繁体   English

如何从 Xamarin MVMCross 中的剃刀视图正确加载生成的 PDF 中的字体?

[英]How can I properly load fonts in a generated PDF from a razor view in Xamarin MVVMCross?

I have been working on a custom PDF generation feature in an MVVMCross application.我一直在 MVVMCross 应用程序中研究自定义 PDF 生成功能。 I'm using a razor template in my Core project that ultimately generates the PDF on both iOS and Android.我在我的 Core 项目中使用了一个 razor 模板,它最终在 iOS 和 Android 上生成了 PDF。 For this PDF, I have to use custom truetype fonts, but I have been unable to reference them properly since the HTML from the razor file is passed along the application as a string and then loaded into the PDF file on different devices.对于这个 PDF,我必须使用自定义的 truetype 字体,但我一直无法正确引用它们,因为来自 razor 文件的 HTML 作为字符串在应用程序中传递,然后加载到不同设备上的 PDF 文件中。 The only way I found around this so far is to include the base64 version of each font in the razor file itself, but this ends up slowing down the file whenever I try to open it to make changes.到目前为止,我找到的唯一方法是在剃刀文件本身中包含每种字体的 base64 版本,但这最终会在我尝试打开文件进行更改时减慢文件速度。 Is there any way to reference the fonts properly so that they are available when the html is written to the PDF?有什么方法可以正确引用字体,以便在将 html 写入 PDF 时它们可用?

I was also able to get it working by adding the Base64 fonts to a constants file and then referencing those constants, but that just moves the slow file load time from the razor file to my constants file.我还可以通过将 Base64 字体添加到常量文件然后引用这些常量来使其工作,但这只会将缓慢的文件加载时间从 razor 文件移动到我的常量文件。

我能够通过分别为每个视图项目设置 BaseUrls 来引用包含字体的资源文件夹来解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM