简体   繁体   English

Xamarin.Forms 无法转换 stream 中的 TTF 文件

[英]Xamarin.Forms can't convert TTF file in stream

I'm working on Xamarin.Forms app with help of Syncfusion and want to add Cyrillic support in PDF drawing.I download ArialUnicodeMS.tff added the file in Shared Project in Resources folder and added Build Action Embedded Resource and also added [assembly: ExportFont("ArialUnicodeMS.ttf", Alias = "ArialUni")] in AssemblyInfo.cs . I'm working on Xamarin.Forms app with help of Syncfusion and want to add Cyrillic support in PDF drawing.I download ArialUnicodeMS.tff added the file in Shared Project in Resources folder and added Build Action Embedded Resource and also added [assembly: ExportFont("ArialUnicodeMS.ttf", Alias = "ArialUni")]AssemblyInfo.cs中。 But Syncfusion Pdf Drawing want to access to the TTF file by Stream .但是 Syncfusion Pdf 绘图想要通过Stream访问 TTF 文件。

This is my code:这是我的代码:

var assembly = IntrospectionExtensions.GetTypeInfo(typeof(EmbeddedFont)).Assembly;
Stream stream = assembly.GetManifestResourceStream("MyAppName.ArialUnicodeMS.ttf");
PdfFont font = new PdfTrueTypeFont(stream, 14);

But my string is always null .但我的字符串总是null Where i'm getting wrong?我哪里错了?

The resource is missing.资源丢失。

Most likely it is one of these 3 issues:很可能是以下三个问题之一:

  • the name "MyAppName.ArialUnicodeMS.ttf" has a typo.名称"MyAppName.ArialUnicodeMS.ttf"有错字。
  • the resource is not embedded in the typeof(EmbeddedFont)).Assembly assembly.资源未嵌入typeof(EmbeddedFont)).Assembly程序集中。
  • you have not set the parameter Build Action to Embedded Resource .您尚未将参数Build Action设置为Embedded Resource This is part of the EmbeddedFont project and acts on the ArialUnicodeMS.ttf resource.这是EmbeddedFont项目的一部分,作用于ArialUnicodeMS.ttf资源。

To verify which names are available, you can use:要验证哪些名称可用,您可以使用:

string resourceNames = assembly.GetManifestResourceNames();

You could use the code below to get the stream from the Embeded resource.您可以使用下面的代码从嵌入式资源中获取 stream。

   var assembly = Assembly.GetExecutingAssembly();
        var resourceName = "App28.Trashtalk.ttf";
        Stream stream = assembly.GetManifestResourceStream(resourceName);

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

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