简体   繁体   中英

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 . But Syncfusion Pdf Drawing want to access to the TTF file by Stream .

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 . 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.
  • the resource is not embedded in the typeof(EmbeddedFont)).Assembly assembly.
  • you have not set the parameter Build Action to Embedded Resource . This is part of the EmbeddedFont project and acts on the ArialUnicodeMS.ttf resource.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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