Xamarin - how to import custom font with the FontProvider

3 posts, 1 answers
  1. Guittier
    Guittier avatar
    9 posts
    Member since:
    Mar 2014

    Posted 24 Feb Link to this post


    I'm trying to create a PDF file from a Xamarin app.

    Everything went well until I add text with accent (it's quite embarasing for me, because all my texts are in French).

    I know that the 14 Standard fonts are withou accent. 


    So i try to add a FontsProvider to add a MyriadPro.ttf file (which is also Embedded a ressource in my Android and Ios projets),  as explained here : https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/cross-platform , with the using of the Environment.SpecialFolder.Fonts folder

    I put the provider class and initiate it in my create method.

    But when i don't know how to add the .tff file to the Environment.SpecialFolder.Fonts



    When a call my fontfamily with this line (from the Xamarin sample app) :  this.SetTextProperties(block, RgbColors.Black, 25, new FontFamily("MyriadPro"))

    The custom Fontprovider is called as expected, but a have a exception, because the folder : /data/user/0/com.xxx.xxxx/files/.fonts is not found

    My question is : how to add my ttf to the SpecialFolder.fonts , in my Android and Ios project ?


    Thanks for you help, 

  2. Answer
    Yana avatar
    5042 posts

    Posted 25 Feb Link to this post

    Hello Guittier,

    Please take a look at the following kb article which demonstrates how you can add a non-embedded font to Xamarin project and register it through the PdfProcessing FontsRepository class:

    How to embed TrueType fonts in PdfViewer with PdfProcessing library

    Basically, you should add the .ttf file to the Xamarin.Forms project as Embedded Resource, then extract the font data and apply it through the RegisterFont and TryCreateFont methods of the FontsRepository class.

    Please give it a try and let me know if you have any additional questions or concerns.

    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

  3. Guittier
    Guittier avatar
    9 posts
    Member since:
    Mar 2014

    Posted 25 Feb in reply to Yana Link to this post

    Thanks for your answer, it works !!!


Back to Top