/** * Set visible signature designer for a new signature field. * * @param filename * @param x position of the signature field * @param y position of the signature field * @param zoomPercent increase (positive value) or decrease (negative value) image with x percent. * @param imageStream input stream of an image. * @param page the signature should be placed on * @throws IOException */ public void setVisibleSignDesigner(String filename, int x, int y, int zoomPercent, InputStream imageStream, int page) throws IOException { visibleSignDesigner = new PDVisibleSignDesigner(filename, imageStream, page); visibleSignDesigner.xAxis(x).yAxis(y).zoom(zoomPercent).adjustForRotation(); }
/** * Constructor. * * @param document Already created PDDocument of your PDF document. * @param imageStream Image as a stream. * @param page The 1-based page number for which the page size should be calculated. * @throws IOException If we can't read, flush, or can't close stream. */ public PDVisibleSignDesigner(PDDocument document, InputStream imageStream, int page) throws IOException { readImageStream(imageStream); calculatePageSize(document, page); }
/** * Constructor. * * @param filename Path of the PDF file * @param image * @param page The 1-based page number for which the page size should be calculated. * @throws IOException */ public PDVisibleSignDesigner(String filename, BufferedImage image, int page) throws IOException { // set visible signature image setImage(image); // calculate height and width of document page calculatePageSizeFromFile(filename, page); }
/** * Constructor. * * @param document Already created PDDocument of your PDF document. * @param image * @param page The 1-based page number for which the page size should be calculated. */ public PDVisibleSignDesigner(PDDocument document, BufferedImage image, int page) { setImage(image); calculatePageSize(document, page); }
@Override public void createSignatureRectangle(PDSignatureField signatureField, PDVisibleSignDesigner properties) throws IOException { PDRectangle rect = new PDRectangle(); rect.setUpperRightX(properties.getxAxis() + properties.getWidth()); rect.setUpperRightY(properties.getTemplateHeight() - properties.getyAxis()); rect.setLowerLeftY(properties.getTemplateHeight() - properties.getyAxis() - properties.getHeight()); rect.setLowerLeftX(properties.getxAxis()); signatureField.getWidgets().get(0).setRectangle(rect); pdfStructure.setSignatureRectangle(rect); LOG.info("Signature rectangle has been created"); }
pdfBuilder.createAffineTransform(properties.getTransform()); AffineTransform transform = pdfStructure.getAffineTransform(); pdfBuilder.createFormatterRectangle(properties.getFormatterRectangleParameters()); PDRectangle bbox = pdfStructure.getFormatterRectangle(); pdfBuilder.createSignatureImage(template, properties.getImage());
@Override public void createPage(PDVisibleSignDesigner properties) { PDPage page = new PDPage(new PDRectangle(properties.getPageWidth(), properties.getPageHeight())); pdfStructure.setPage(page); LOG.info("PDF page has been created"); }
/** * Constructor. * * @param filename Path of the PDF file * @param imageStream image as a stream * @param page The 1-based page number for which the page size should be calculated. * @throws IOException */ public PDVisibleSignDesigner(String filename, InputStream imageStream, int page) throws IOException { // set visible signature image Input stream readImageStream(imageStream); // calculate height and width of document page calculatePageSizeFromFile(filename, page); }
/** * Constructor. * * @param documentStream Original PDF document as stream * @param imageStream Image as a stream * @param page The 1-based page number for which the page size should be calculated. * @throws IOException */ public PDVisibleSignDesigner(InputStream documentStream, InputStream imageStream, int page) throws IOException { // set visible signature image Input stream readImageStream(imageStream); // calculate height and width of document page calculatePageSizeFromStream(documentStream, page); }
/** * Constructor. * * @param documentStream Original PDF document as stream * @param image * @param page The 1-based page number for which the page size should be calculated. * @throws IOException */ public PDVisibleSignDesigner(InputStream documentStream, BufferedImage image, int page) throws IOException { // set visible signature image setImage(image); // calculate height and width of document page calculatePageSizeFromStream(documentStream, page); }
PDVisibleSignDesigner visibleSig = new PDVisibleSignDesigner(args[2], image, 3); visibleSig.xAxis(0).yAxis(0).zoom(-75).signatureFieldName("ApplicantSignature"); PDVisibleSigProperties signatureProperties = new PDVisibleSigProperties(); signatureProperties.signerName("name").signerLocation("location") .signatureReason("Security").preferredSize(0).page(3) .visualSignEnabled(true).setPdVisibleSignature(visibleSig) .buildSignature();
private void calculatePageSizeFromStream(InputStream documentStream, int page) throws IOException { try (PDDocument document = PDDocument.load(documentStream)) { // calculate height and width of document page calculatePageSize(document, page); } }
/** * * @return template height */ protected float getTemplateHeight() { return getPageHeight(); }
@Override public void createSignatureRectangle(PDSignatureField signatureField, PDVisibleSignDesigner properties) throws IOException { PDRectangle rect = new PDRectangle(); rect.setUpperRightX(properties.getxAxis() + properties.getWidth()); rect.setUpperRightY(properties.getTemplateHeight() - properties.getyAxis()); rect.setLowerLeftY(properties.getTemplateHeight() - properties.getyAxis() - properties.getHeight()); rect.setLowerLeftX(properties.getxAxis()); signatureField.getWidgets().get(0).setRectangle(rect); pdfStructure.setSignatureRectangle(rect); LOG.info("Signature rectangle has been created"); }
pdfBuilder.createAffineTransform(properties.getTransform()); AffineTransform transform = pdfStructure.getAffineTransform(); pdfBuilder.createFormatterRectangle(properties.getFormatterRectangleParameters()); PDRectangle bbox = pdfStructure.getFormatterRectangle(); pdfBuilder.createSignatureImage(template, properties.getImage());
@Override public void createPage(PDVisibleSignDesigner properties) { PDPage page = new PDPage(new PDRectangle(properties.getPageWidth(), properties.getPageHeight())); pdfStructure.setPage(page); LOG.info("PDF page has been created"); }
/** * Constructor. * * @param document Already created PDDocument of your PDF document. * @param image * @param page The 1-based page number for which the page size should be calculated. */ public PDVisibleSignDesigner(PDDocument document, BufferedImage image, int page) { setImage(image); calculatePageSize(document, page); }
/** * Constructor. * * @param filename Path of the PDF file * @param imageStream image as a stream * @param page The 1-based page number for which the page size should be calculated. * @throws IOException */ public PDVisibleSignDesigner(String filename, InputStream imageStream, int page) throws IOException { // set visible signature image Input stream readImageStream(imageStream); // calculate height and width of document page calculatePageSizeFromFile(filename, page); }