使用 iText 完成的数字签名中的日期时区
我正在使用 iText 7 对文档进行数字签名。我有一个用例,我希望在数字标牌的“日期”部分中添加自定义时区。 例如日期:2022.04.06 18:12:10 UTC - 5:00
。 UTC-5:00 并不那么重要,它可以是 EST
或 CDT
。但时间必须在特定时区。我尝试在 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论