使用 iText 完成的数字签名中的日期时区

发布于 2025-01-19 19:59:19 字数 2091 浏览 0 评论 0原文

我正在使用 iText 7 对文档进行数字签名。我有一个用例,我希望在数字标牌的“日期”部分中添加自定义时区。 例如日期:2022.04.06 18:12:10 UTC - 5:00。 UTC-5:00 并不那么重要,它可以是 ESTCDT。但时间必须在特定时区。我尝试在 pdfSigner 中设置签名日期,该日期在内部也将其设置为 PdfSignatureAppearance,但日期仍然以 UTC 形式出现。

PdfSigner pdfSigner = new PdfSigner(pdfReader, pdfWriter.getOutputStream(), new StampingProperties().useAppendMode());
            pdfSigner.setSignDate(cal);
            log.debug("Time Zone" + pdfSigner.getSignDate().getTimeZone());


            String base64 = signedCoordinate.getBase64Image();
            if (isNotBlank(base64)) {
                base64 = new String(base64.substring(base64.indexOf(",") + 1));
            }

            byte[] imageBytes = Base64.getDecoder().decode(base64);

            ImageData imageData = ImageDataFactory.create(imageBytes);

            float position =
                    (Math.abs(signedCoordinate.getCoordinateC() - signedCoordinate.getCoordinateA())
                            - (signedCoordinate.getWidth())) / 2;

            Rectangle rectangle = new Rectangle(signedCoordinate.getCoordinateA() + position, signedCoordinate.getCoordinateB(), Math.abs(signedCoordinate.getWidth()) + 30f, Math.abs(signedCoordinate.getCoordinateD() - signedCoordinate.getCoordinateB()));
            com.itextpdf.signatures.PdfSignatureAppearance appearanceFromItext = pdfSigner.getSignatureAppearance();
            appearanceFromItext.setPageNumber(signedCoordinate.getPageNumber());
            appearanceFromItext.setImage(imageData);
            appearanceFromItext.setPageRect(rectangle);
            appearanceFromItext.setReason("whadupp");
            appearanceFromItext.setLocation("home");

注意:cal 变量具有我需要的时区。而且,在 iText7 的 signDetached 方法中,我可以看到评论,上面写着

dic.setDate(new PdfDate(getSignDate())); // time-stamp will over-rule this

Is it possible to have time in a different timezone 签名图像

I am using iText 7 to digitally sign documents. I have a use case in which I want a custom timezone to come in the "Date" section of the digital sign.
e.g. Date : 2022.04.06 18:12:10 UTC - 5:00. UTC-5:00 is not that important, it can be EST or CDT. But the time has to be in a particular time zone. I tried setting the sign date in pdfSigner which internally sets it to PdfSignatureAppearance as well, but the Date is still coming in UTC.

PdfSigner pdfSigner = new PdfSigner(pdfReader, pdfWriter.getOutputStream(), new StampingProperties().useAppendMode());
            pdfSigner.setSignDate(cal);
            log.debug("Time Zone" + pdfSigner.getSignDate().getTimeZone());


            String base64 = signedCoordinate.getBase64Image();
            if (isNotBlank(base64)) {
                base64 = new String(base64.substring(base64.indexOf(",") + 1));
            }

            byte[] imageBytes = Base64.getDecoder().decode(base64);

            ImageData imageData = ImageDataFactory.create(imageBytes);

            float position =
                    (Math.abs(signedCoordinate.getCoordinateC() - signedCoordinate.getCoordinateA())
                            - (signedCoordinate.getWidth())) / 2;

            Rectangle rectangle = new Rectangle(signedCoordinate.getCoordinateA() + position, signedCoordinate.getCoordinateB(), Math.abs(signedCoordinate.getWidth()) + 30f, Math.abs(signedCoordinate.getCoordinateD() - signedCoordinate.getCoordinateB()));
            com.itextpdf.signatures.PdfSignatureAppearance appearanceFromItext = pdfSigner.getSignatureAppearance();
            appearanceFromItext.setPageNumber(signedCoordinate.getPageNumber());
            appearanceFromItext.setImage(imageData);
            appearanceFromItext.setPageRect(rectangle);
            appearanceFromItext.setReason("whadupp");
            appearanceFromItext.setLocation("home");

note : cal variable has the timezone I need. And, in signDetached method of iText7, i can see comment which says

dic.setDate(new PdfDate(getSignDate())); // time-stamp will over-rule this

Is it possible to have time in a different timezone
sign image?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文