如何计算iText中的字符串宽度? [英] How to calculate the string width in iText?

查看:1360
本文介绍了如何计算iText中的字符串宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iText来编写PDF。在某些情况下,我需要使用 SetVisibleSignature 函数对PDF进行签名。使用此函数,我们需要指定要将内容写入的矩形。

I am using iText to write a PDF. In some cases, I need to sign the PDF with the SetVisibleSignature function. With this function, we need to designate the rectangle that we will write the content into.

但是我很难计算字符串的宽度,所以我可以在设置PDF上的签名之前设置矩形。

But it's hard for me to calculate how wide the string will be, so that I can set the rectangle before setting a signature on the PDF.

如何计算iText中的字符串宽度?

How can I calculate the string width in iText?

推荐答案

您可以使用 BaseFont.getWidthPoint(String text,float fontSize)来获取pt中字符串的宽度。

You can use BaseFont.getWidthPoint(String text, float fontSize) to get the width of the string in pt.

或者将字符串放入Chunk并执行 chunk.getWidthPoint()

Or put the string in a Chunk and do chunk.getWidthPoint()

这篇关于如何计算iText中的字符串宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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