Why is the name, location, and reason missing from the visual signature?
They are not, because they are not drawn.
By default, iText presents a rendered signature, adding this information to the renderer.
By default, the PDFBox ' PDVisibleSigBuilder for presenting a rendered signature does not have this information.
Wrong or wrong, both are simply the default values.
The canonical place where people should look for such information is, finally, a signature panel.
How can i fix this?
The actual contents of the signature render are created by the PDVisibleSigBuilder instance during signatureProperties.buildSignature() :
public void buildSignature() throws IOException { PDFTemplateBuilder builder = new PDVisibleSigBuilder(); PDFTemplateCreator creator = new PDFTemplateCreator(builder); setVisibleSignature(creator.buildPDF(getPdVisibleSignature())); }
Thus replacing
signatureProperties.signerName(name).signerLocation(location) .signatureReason(reason).preferredSize(0).page(1) .visualSignEnabled(true).setPdVisibleSignature(signatureDesigner) .buildSignature();
in your code
signatureProperties.signerName(name).signerLocation(location) .signatureReason(reason).preferredSize(0).page(1) .visualSignEnabled(true).setPdVisibleSignature(signatureDesigner); PDFTemplateBuilder builder = new ExtSigBuilder(); PDFTemplateCreator creator = new PDFTemplateCreator(builder); signatureProperties.setVisibleSignature(creator.buildPDF(signatureProperties.getPdVisibleSignature()));
for a custom version of ExtSigBuilder this ExtSigBuilder class, you can draw anything, for example:
class ExtSigBuilder extends PDVisibleSigBuilder { String fontName; public void createImageForm(PDResources imageFormResources, PDResources innerFormResource, PDStream imageFormStream, PDRectangle formrect, AffineTransform affineTransform, PDJpeg img) throws IOException { super.createImageForm(imageFormResources, innerFormResource, imageFormStream, formrect, affineTransform, img); PDFont font = PDType1Font.HELVETICA; fontName = getStructure().getImageForm().getResources().addFont(font); logger.info("Added font to image form: " + fontName); } public void injectAppearanceStreams(PDStream holderFormStream, PDStream innterFormStream, PDStream imageFormStream, String imageObjectName, String imageName, String innerFormName, PDVisibleSignDesigner properties) throws IOException { super.injectAppearanceStreams(holderFormStream, innterFormStream, imageFormStream, imageObjectName, imageName, innerFormName, properties); String imgFormComment = "q " + 100 + " 0 0 50 0 0 cm /" + imageName + " Do Q\n"; String text = "BT /" + fontName + " 10 Tf (Hello) Tj ET\n"; appendRawCommands(getStructure().getImageFormStream().createOutputStream(), imgFormComment + text); logger.info("Added text commands to image form: " + text); } }
writes "Hello" in Helvetica 10 in the upper left corner of the image form (the form actually displays something).
PS: In my opinion, the object-oriented structure behind this should be completely redone.