1 year ago

#382374

test-img

Kalpit

Date timezone in digital signature done using iText

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?

java

itext

itext7

0 Answers

Your Answer

Accepted video resources