gpt4 book ai didi

java - 在 android 中使用 itext 生成 Pdf 用于 Bangla 文本

转载 作者:行者123 更新时间:2023-11-29 02:35:29 31 4
gpt4 key购买 nike

我正在使用 i-text 从我的 android 应用程序生成 pdf。但它适用于英文字体。当我试图为我的语言环境 Bangla 生成 pdf 时,我遇到了一些问题。从一些博客中得到一些提示后,我按照下面提到的方式得到了实现:

String fontName = "Nikosh.ttf";
InputStream is = context.getAssets().open(fontName);
int size = is.available();
byte[] buffer = new byte[size];
int a = is.read(buffer);
BaseFont customFont = BaseFont.createFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, true, buffer, buffer);
Font banglaFont = new Font(customFont, 12);

现在输出看起来像这样:

这是使用 bangla 字体的 Bangla 文本的输出

image

但是输出文本被破坏了。而原来的看起来像这样:

孟加拉语原文

image2

任何有关如何在 android 中解决此类 unicode 问题的帮助将不胜感激。注意我正在使用 i-text 5.5.x

最佳答案

也使用显示的字体。

BaseFont base = BaseFont.createFont("c:/windows/fonts/arial.ttf", BaseFont.WINANSI);
Font font = new Font(base, 11f, Font.BOLD);

关于java - 在 android 中使用 itext 生成 Pdf 用于 Bangla 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47363108/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com