In my previous post, I guided how to find all the images that are signatures place holders. In this post, I will tell how to replace or merge them with your fancy signature image. First, you need to prepare your fancy signature image. You can try with: https://www.sign.plus/online-signature-generator And create a BufferedImage from your signature. In the RenderListener implementation, we detected the image object that might be the signature place holder. Then 4 steps need to be done to merge your fancy contract. PdfReader::killIndirect, remove the connectioncom.itextpdf.text.Image::getInstance(bufferedImage) create a new mask ImagePdfWriter writer = pdfStamper.getWriter();create indirect connection with the new signature imagePdfReader.killIndirect(currentImg); BufferedImage bufferedImage = ImageIO .read(new ByteArrayInputStream(imageBytes)); if (bufferedImage != null) { Image signatureImage = Image.getInstance(bufferedImage, null); Image maskImage = signatureImage.getImageMask(); if (maskImage != null) { log.error("maskImage {}", maskImage.getAbsoluteX()); writer.addDirectImageSimple(maskImage); } signatureImage.scaleToFit(targetWidth.floatValue(), targetHeight.floatValue()); writer.addDirectImageSimple(signatureImage, (PRIndirectReference) obj); } Apply signatures programiclly via itextpdf |
Comments
Post a Comment