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

查看:50
本文介绍了如何计算 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天全站免登陆