Itext PDF writer,有没有办法在pdf中允许unicode下标符号? (没有setTextRise) [英] Itext PDF writer, Is there any way to allow unicode subscript symbol in the pdf? (Without setTextRise)

查看:147
本文介绍了Itext PDF writer,有没有办法在pdf中允许unicode下标符号? (没有setTextRise)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用Itext PDF writer创建PDF文件。我发现默认字体中不允许使用上标(0,4,5,6,7,8,9)和下标(0,1,2,3,4,5,6,7,8,9) 。在默认设置中,PDF文本中仅允许使用上标1,2,3。

I have been trying to create PDF files using Itext PDF writer. I have found that Superscript (0,4,5,6,7,8,9) and Subscript (0,1,2,3,4,5,6,7,8,9) are not allowed in the default font. Only Superscript 1,2,3 are allowed in PDF texts in the default setting.

我的PDF中的字符串包含下标和上标字符,有没有办法可以用PDF格式显示它们?

A String in my PDF contains subscript and superscript characters, is there a way i can display them in PDF?

我搜索并找到:


  1. setTextRise()方法用于改变文本相对于当前行的位移,I不能使用它,因为我不知道哪些字符是超级/子脚本。

  2. 是否有设置将文本的编码/字体更改为UTF-8,以便它允许所有的unicode符号?

或者其他方式,因为我必须显示化学符号,如H 2 SO 6,O 2等。

Or some other way, because i have to show chemical symbols like H₂SO⁴, O₂ etc.

这对你有很大帮助,谢谢!

It'd be of great help, thanks!

推荐答案

请看一下 SubSuperScript

Please take a look at the SubSuperScript example I wrote in answer to your question. I'm writing H₂SO⁴ like this:

BaseFont bf = BaseFont.createFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font f = new Font(bf, 10);
Paragraph p = new Paragraph("H\u2082SO\u2074", f);
document.add(p);

我在维基百科上找到了特定字符的值: http://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts

I've found the values of the specific characters on Wikipedia: http://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts

As你可以看到,iText完全能够显示用下标或上标写的特殊字符: sub_superscript.pdf

As you can see, iText is perfectly capable to show the special characters written in subscript or superscript: sub_superscript.pdf

我写这个例子时遇到的主要问题是找到支持特定字形的字体。这就是我在之前的评论中解释的内容。我最终使用了一种名为Carbo Regular的字体。

The main problem I had when I wrote this example was finding a font that supported the specific glyphs. That's what I explained in my earlier comment. I ended up using a font called "Carbo Regular".

这篇关于Itext PDF writer,有没有办法在pdf中允许unicode下标符号? (没有setTextRise)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆