为什么PdfFontFactory无法注册我的统一android游戏中应用程序持久数据路径中的本地语言字体?

问题描述 投票:0回答:1

我正在使用Itext7以我的本地语言创建pdf。在standalone_windows上一切正常,但在android中,PdfFontFactory无法注册这些字体。

在Standalone_Windows中 我从流媒体资产中获取原始文件,它们可以正常工作。

在Android中,我正在使用UnityWebRequest将字体从流媒体资源路径下载到持久数据路径

这是用于从流媒体资源下载字体字节并将其写入持久性数据路径的代码:

 string fontpath1 = System.IO.Path.Combine(Application.streamingAssetsPath, "LEOPALMHINDI15K710.TTF");
    string fontpath2 = System.IO.Path.Combine(Application.streamingAssetsPath, "LEOPALMHINDI14K240.TTF");

    //Request Hindi Font 1

    UnityWebRequest request = UnityWebRequest.Get(fontpath1);
    request.SendWebRequest();
    while (!request.isDone)
    {


    }
    System.IO.File.WriteAllBytes(System.IO.Path.Combine(Application.persistentDataPath , "LEOPALMHINDI15K710.TTF"),request.downloadHandler.data); 
    request.Dispose();
    //Request Hindi Font 2

    UnityWebRequest font2 = UnityWebRequest.Get(fontpath2);
    font2.SendWebRequest();
    while (!font2.isDone)
    {


    }
    System.IO.File.WriteAllBytes(System.IO.Path.Combine(Application.persistentDataPath, "LEOPALMHINDI14K240.TTF"), font2.downloadHandler.data);
    font2.Dispose();

这是我使用filePath字符串读取字体文件的代码:

    string HFOnt = System.IO.Path.Combine(Application.persistentDataPath, "LEOPALMHINDI15K710.TTF");
    string HFOnt2 = System.IO.Path.Combine(Application.persistentDataPath, "LEOPALMHINDI14K240.TTF");
    PdfFontFactory.Register(HFOnt, "HindiFont1");
    PdfFont myHindiFont1 = PdfFontFactory.CreateRegisteredFont("HindiFont1", PdfEncodings.IDENTITY_H, true);

    PdfFontFactory.Register(HFOnt2, "HindiFont2");
    PdfFont myHindiFont2 = PdfFontFactory.CreateRegisteredFont("HindiFont2", PdfEncodings.IDENTITY_H, true);


    //Create Writer

    if (File.Exists(path))
    {

        File.Delete(path);

    }
    PdfWriter writer = new PdfWriter(path);




    //Create Pdf Document Object
    PdfDocument pdf = new PdfDocument(writer);

    //Create A Document
    Document document = new Document(pdf, PageSize.A4);
    document.SetMargins(90f, 36f, 120f, 36f);

    PdfPage page1 = pdf.AddNewPage();
    document.Add(new iText.Layout.Element.AreaBreak());

    //Get Page Size and Canvas
    PdfCanvas canvas = new PdfCanvas(page1);
    Rectangle pageSize = page1.GetPageSize();

    canvas.BeginText()
      .MoveText(pageSize.GetWidth() / 2-35, pageSize.GetHeight() - 400)
      .SetFontAndSize(myHindiFont1, 9f)
      .ShowText("lfdZy uacj dqvk uacj gS")
      .EndText();

     document.Close();

我正在使用UnityWebRequest将这些字体从流媒体资源下载到持久数据路径。

[我在处理Unity Web请求后使用File.Exists在持久数据路径中检查文件是否存在,并且它在两个字体文件的跟踪中都返回true。

这是我在设备监视器中遇到的错误:

03-02 13:40:57.084:E / Unity(18347):NotSupportedException:找不到编码1252数据。确保已安装并启用了正确的国际代码集程序集。

03-02 13:40:57.084:E / Unity(18347):在<7ba07f088431485bb722f3b3373e87ee>:0]中的System.Text.Encoding.GetEncoding(System.Int32代码页)[0x0023f]中

03-02 13:40:57.084:E / Unity(18347):位于<7ba07f088431485bb722f3b3373e87ee>:0]中的System.Text.Encoding.GetEncoding(System.String名称)[0x00012]

03-02 13:40:57.084:E / Unity(18347):在iText.IO.Util.JavaUtil.GetStringForBytes(System.Byte []字节,System.Int32偏移量,System.Int32长度,System.String编码)[0x00000]在<57da1b8d8a184e278c732544ebe6412a>:0

03-02 13:40:57.084:E / Unity(18347):在iText.IO.Util.JavaUtil.GetStringForBytes(System.Byte []字节,System.String编码)[0x00000]在<57da1b8d8a184e278c732544ebe6412a>:0中

03-02 13:40:57.084:E / Unity(18347):位于iText.IO.Source.RandomAccessFileOrArray.ReadString(System.Int32长度,System.String编码)[0x0000e]在<57da1b8d8a184e278c732544ebe6412a>:0]中

03-02 13:40:57.084:E / Unity(18347):在iText.IO.Font.OpenTypeParser.ReadStandardString(System.Int32长度)[0x00000]在<57da1b8d8a184e278c732544ebe6412a>:0]中

03-02 13:40:57.084:E / Unity(18347):在iText.IO.Font.OpenTypeParser.Process()[0x00

有没有人可以研究这个帮助我注册字体?

我正在使用Itext7以我的本地语言创建pdf。在standalone_windows上一切正常,但在android中,PdfFontFactory无法注册这些字体。在Standalone_Windows中,我提取...

仅在我的项目中保存了i18n.dll文件,它可以工作。感谢之前的所有主题。

android unity3d pdf-generation itext7 true-type-fonts
1个回答
0
投票

仅在我的项目中保存了i18n.dll文件,它可以工作。感谢之前的所有主题。

© www.soinside.com 2019 - 2024. All rights reserved.