Following is the code I am using to place digital signatures on standard four coordinates ie top left, top right, bottom left, bottom right. However, its not working correctly for top left.
PdfReader reader = new PdfReader(src);//src being file path of pdf being signed
Rectangle cropBox = reader.getCropBox(1);
if(signaturePosition.equalsIgnoreCase("bottom-left"))
appearance.setVisibleSignature(new Rectangle(cropBox.getLeft(), cropBox.getBottom(),
cropBox.getLeft(width), cropBox.getBottom(height)), 1, "first");
if(signaturePosition.equalsIgnoreCase("bottom-right"))
appearance.setVisibleSignature(new Rectangle(cropBox.getRight(width), cropBox.getBottom(),
cropBox.getRight(), cropBox.getBottom(height)), 1, "first");
if(signaturePosition.equalsIgnoreCase("top-left"))
appearance.setVisibleSignature(new Rectangle(72, 732, 144, 780), 1, "first");
if(signaturePosition.equalsIgnoreCase("top right"))
appearance.setVisibleSignature(new Rectangle(cropBox.getRight(width), cropBox.getTop(height),
cropBox.getRight(), cropBox.getTop()), 1, "first");
Its required to position the signature anywhere on pdf depending upon coordinates provided by the user. To get user's coordinates, we are using a pdf xpro template with a textbox placed over it(user will upload the template and place the textbox where he requires signature to be placed), using that textbox coordinates with its height and width as reference we will position the signature on the pdf.
I need help on understanding how appearance.setVisibleSignature() method works wrt the Rectangle object passed to it, because for each quadrant of the page(considering the center of the page as origin) the parameters are being passed differently for top left, top right, bottom left and bottom right respectively.