仅使用itextpdf使用字母(拉丁语)的HTML的PDF

发布于 2025-01-26 16:29:08 字数 930 浏览 2 评论 0原文

我相信,对于那些经验丰富的人来说,我的问题的答案非常容易,我事先感谢您。

也就是说,我设法从TextView BodyTextTitletext中导出PDF文件,但是我的问题是只有字母(拉丁)字母可以在该PDF文件中看到,我可以't看到一个阿拉伯语,西里尔,印度人或希伯来语等的例子,任何人都可以帮助我,谢谢!!!!!!!!!

在Gradle I中使用:实现'com.itextpdf.tool:xmlworker:5.5.3'

OutputStream file = new FileOutputStream(new File("MyPath"));
                            
Document document = new Document (PageSize.A4);

PdfWriter.getInstance(document, file);
                            
document.open();
                            
Paragraph title = new Paragraph();
title.add(titleText.getText().toString());
title.setSpacingAfter(12.0f);
title.setAlignment(Element.ALIGN_CENTER);
document.add(title);
document.add(new Paragraph("\n"));
HTMLWorker htmlWorker = new HTMLWorker(document);
htmlWorker.parse(new StringReader(Html.toHtml((Spanned) bodyText.getText())));
    
document.close();
file.close();

I believe that the answer to my question is very easy for those who have had experience with this, and I thank you in advance.

Namely, I managed to export a PDF file from TextView bodyText and titleText, but my problem is that only alphabetic (Latin) letters can be seen in that PDF file, I can't see an example in Arabic, Cyrillic, Indian or Hebrew, etc. Can anyone help me, thanks !!!!!!!!

In Gradle I use: implementation 'com.itextpdf.tool:xmlworker:5.5.3'

OutputStream file = new FileOutputStream(new File("MyPath"));
                            
Document document = new Document (PageSize.A4);

PdfWriter.getInstance(document, file);
                            
document.open();
                            
Paragraph title = new Paragraph();
title.add(titleText.getText().toString());
title.setSpacingAfter(12.0f);
title.setAlignment(Element.ALIGN_CENTER);
document.add(title);
document.add(new Paragraph("\n"));
HTMLWorker htmlWorker = new HTMLWorker(document);
htmlWorker.parse(new StringReader(Html.toHtml((Spanned) bodyText.getText())));
    
document.close();
file.close();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一身软味 2025-02-02 16:29:08

我相信问题是您在导出时决定使用的字体。 某些字体不支持非拉丁字符。

因此,您可以使用以下字体:

  • code2000
  • arial unicode ms

与itextpdf一起使用它:单击此处

font = PdfFontFactory.createFont(FontConstants.CODE2000)
text1.setFont(font);

I believe the problem is the font that you decided to use when exporting. Some fonts do not support non-Latin characters.

As a result you can use fonts like:

  • CODE2000
  • Arial Unicode MS

To use it with itextpdf I refrenced this: Click here

font = PdfFontFactory.createFont(FontConstants.CODE2000)
text1.setFont(font);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文