删除iText PDF签名中Rectangle的填充 [英] Delete padding of Rectangle in iText PDF signature

查看:841
本文介绍了删除iText PDF签名中Rectangle的填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小应用程序,可以使用iText在JAVA中为PDF添加签名. 这是代码的一部分:

I have a little app to add a signature to a PDF in JAVA using iText. This is a fragment of the code:

PdfReader           reader  = new PdfReader(pdfBytes);
FileOutputStream    fos     = new FileOutputStream(new File("/home/john/signedPdf.pdf"));
PdfStamper          stamper = PdfStamper.createSignature(
                            reader, 
                            fos, 
                            '\0', 
                            new File("/home/john/"), 
                            true
    );
PdfSignatureAppearance signatureAppearance = stamper.getSignatureAppearance();
signatureAppearance.setRenderingMode(PdfSignatureAppearance.RenderingMode.DESCRIPTION);
Rectangle rectangle = new Rectangle(
                36,
                748 - 20 * (next - 1) ,
                144,
                780 - 20 * (next - 1)
    );
rectangle.normalize();
signatureAppearance.setVisibleSignature(
        rectangle, 
        1, contact);

PDF的签名正确,但是矩形中的可见符号带有填充,一个矩形超过第二个,第二个超过第三个,依此类推. 这是示例图像: 存在一种删除此填充并使一个矩形越过另一个矩形的方法. 预先感谢

The PDF is signed good, but the visible sign in the rectangle has a padding and one rectangle get over the second, and second get over third, etc. This is the example image: Exist a way to delete this padding and evit one rectangle get over other. Thanks in advance

推荐答案

您将这样创建的矩形用于签名

You use rectangles created like this for your signatures

Rectangle rectangle = new Rectangle(
                36,
                748 - 20 * (next - 1) ,
                144,
                780 - 20 * (next - 1)
    );

其中(如注释中所阐明),整数next可以具有签名的连续值,例如1和2.

where (as clarified in comments) the integer next can have consecutive values for the signatures, e.g. 1 and 2.

但这意味着您实际上要求重叠的签名矩形!例如.对于值1和2,您将得到:

But this means that you actually ask for overlapping signature rectangles! E.g. for for the values 1 and 2 you get:

  • next == 1-矩形顶部 y :780;矩形底部 y :748
  • next == 2-矩形顶部 y :760;矩形底部 y :728
  • next == 1 - rectangle top y: 780; rectangle bottom y: 748
  • next == 2 - rectangle top y: 760; rectangle bottom y: 728

因此这些矩形在760和748之间重叠 y .

So these rectangles overlap for y between 760 and 748.

如果您不希望矩形重叠,则 y 阶跃因子(当前为20)必须至少与顶部和底部 y 坐标起始值(当前为780-748 = 32).

If you don't want your rectangle to overlap, the y step factor (currently 20) must be at least as large as the difference between the top and bottom y coordinate start values (currently 780 - 748 = 32).

例如您可以使用32的步进系数

E.g. you can use a step factor of 32

Rectangle rectangle = new Rectangle(
                36,
                748 - 32 * (next - 1) ,
                144,
                780 - 32 * (next - 1)
    );

或20的矩形高度

Rectangle rectangle = new Rectangle(
                36,
                760 - 20 * (next - 1) ,
                144,
                780 - 20 * (next - 1)
    );

代替当前的矩形尺寸和位置.

instead of your current rectangle dimensions and locations.

这篇关于删除iText PDF签名中Rectangle的填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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