List of usage examples for com.itextpdf.text.pdf PdfAppearance createAppearance
public static PdfAppearance createAppearance(PdfWriter writer, float width, float height)
From source file:com.ots.jsp1.itext.ADAStamper.java
License:Open Source License
public void addADAAsWatermark(InputStream inStream, OutputStream outputStream, String ADA) throws DocumentException, IOException { PdfStamper stamper = null;//from w w w . j a v a2 s .c o m PdfReader reader = null; try { reader = new PdfReader(inStream); //The zero byte means we dont want to change the version number of the PDF file. //true->not to change any of the original bytes stamper = new PdfStamper(reader, outputStream, '\0', true); int numberOfPages = reader.getNumberOfPages(); for (int currentPage = 1; currentPage <= numberOfPages; currentPage++) { PdfAppearance canvas = PdfAppearance.createAppearance(stamper.getWriter(), 100, 30); canvas.setFontAndSize( BaseFont.createFont(fontFilePath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED, true), 11); Rectangle pageSize = reader.getPageSizeWithRotation(currentPage); Rectangle watermarkPosition = new Rectangle(pageSize.getRight() - 150, pageSize.getTop() - 30, pageSize.getRight() - 50, pageSize.getTop() - 10, 0); PdfAnnotation annotation = PdfAnnotation.createFreeText(stamper.getWriter(), watermarkPosition, ADA, canvas); annotation.put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_READONLY)); // annotation.put(PdfName.FONT, canvas); // PdfAnnotation annotation = PdfAnnotation.createText(stamper.getWriter(), watermarkPosition, "", ADA, true, "Key"); // PdfBorderDictionary borderDictionary = new PdfBorderDictionary(0, PdfBorderDictionary.STYLE_SOLID); annotation.setBorderStyle(borderDictionary); stamper.addAnnotation(annotation, currentPage); } } finally { stamper.close(); reader.close(); } }
From source file:gov.nih.nci.firebird.service.registration.AbstractPdfWriterGenerator.java
License:Open Source License
private void addSignatureField() throws DocumentException { PdfFormField field = PdfFormField.createSignature(writer); Rectangle signatureFieldRectangle = new Rectangle(SIGNATURE_FIELD_LOWER_LEFT_X, SIGNATURE_FIELD_LOWER_LEFT_Y, SIGNATURE_FIELD_UPPER_RIGHT_X, SIGNATURE_FIELD_UPPER_RIGHT_Y); field.setWidget(signatureFieldRectangle, PdfAnnotation.HIGHLIGHT_INVERT); field.setFieldName("signature"); field.setFlags(PdfAnnotation.FLAGS_PRINT); field.setPage();/*w w w .ja va 2s .c o m*/ field.setMKBorderColor(BaseColor.BLACK); field.setMKBackgroundColor(BaseColor.WHITE); PdfAppearance appearance = PdfAppearance.createAppearance(writer, SIGNATURE_FIELD_WIDTH, SIGNATURE_FIELD_HEIGHT); appearance.rectangle(SIGNATURE_FIELD_APPEARANCE_X, SIGNATURE_FIELD_APPEARANCE_Y, SIGNATURE_FIELD_APPEARANCE_WIDTH, SIGNATURE_FIELD_APPEARANCE_HEIGHT); appearance.stroke(); field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, appearance); writer.addAnnotation(field); }