/** * Creates a new appearance to be used with form fields. * * @param width the bounding box width * @param height the bounding box height * @return the appearance created */ public PdfAppearance createAppearance(float width, float height) { return createAppearance(width, height, null); }
/** * Creates a new appearance to be used with form fields. * * @param width the bounding box width * @param height the bounding box height * @return the appearance created */ public PdfAppearance createAppearance(float width, float height) { return createAppearance(width, height, null); }
/** * Creates a new appearance to be used with form fields. * * @param width the bounding box width * @param height the bounding box height * @return the appearance created */ public PdfAppearance createAppearance(float width, float height) { return createAppearance(width, height, null); }
PdfContentByte ab = yourPDFWriter.getDirectContent(); // field: PdfFormField.createTextField(...); PdfAppearance ap = ab.createAppearance(320, 30); // size of field field.setDefaultAppearanceString(ap);
//Read the pdf PdfReader reader = new PdfReader(inputstream); //Use PdfStamper in append mode stamp = new PdfStamper(reader, new FileOutputStream(file), '\0', true); //Read the image Image img = Image.getInstance(ImageIO.read(imgStream), null); float w = img.getScaledWidth(); float h = img.getScaledHeight(); Rectangle location = new Rectangle(70, 770 - h, 70 + w, 770); //Create stamp annotation PdfAnnotation stampAnnot = PdfAnnotation.createStamp(stamp.getWriter(), location, null, "ITEXT"); img.setAbsolutePosition(0, 0); //Create new PdfContentByte from the stamp writer //If you use cd = stamp.getOverContent(1) - you'll invalidate the signatures PdfContentByte cb = new PdfContentByte(stamp.getWriter()); PdfAppearance app = cb.createAppearance(w, h); app.addImage(img); stampAnnot.setAppearance(PdfName.N, app); stampAnnot.setFlags(PdfAnnotation.FLAGS_PRINT); stamp.addAnnotation(stampAnnot, 1); reader.close();
private void setCheckboxAppearance( PdfFormField checkboxfield, PdfContentByte canvas, float width ) { PdfAppearance[] onOff = new PdfAppearance[2]; onOff[0] = canvas.createAppearance( width + 2, width + 2 ); onOff[0].rectangle( 1, 1, width, width ); onOff[0].stroke(); onOff[1] = canvas.createAppearance( width + 2, width + 2 ); onOff[1].setRGBColorFill( 255, 128, 128 ); onOff[1].rectangle( 1, 1, width, width ); onOff[1].fillStroke(); onOff[1].moveTo( 1, 1 ); onOff[1].lineTo( width + 1, width + 1 ); onOff[1].moveTo( 1, width + 1 ); onOff[1].lineTo( width + 1, 1 ); onOff[1].stroke(); checkboxfield.setAppearance( PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0] ); checkboxfield.setAppearance( PdfAnnotation.APPEARANCE_NORMAL, "On", onOff[1] ); } }
PdfAppearance tpOff = cb.createAppearance(width, height); PdfAppearance tpOn = cb.createAppearance(width, height);
PdfAppearance tpOff = cb.createAppearance(width, height); PdfAppearance tpOn = cb.createAppearance(width, height);
PdfAppearance tpOff = cb.createAppearance(width, height); PdfAppearance tpOn = cb.createAppearance(width, height);
private void createAppearance( RenderingContext c, ITextOutputDevice outputDevice, BlockBox box, PdfFormField field) { PdfWriter writer = outputDevice.getWriter(); ITextFSFont font = (ITextFSFont)box.getStyle().getFSFont(c); PdfContentByte cb = writer.getDirectContent(); float width = outputDevice.getDeviceLength(getWidth()); float height = outputDevice.getDeviceLength(getHeight()); float fontSize = outputDevice.getDeviceLength(font.getSize2D()); PdfAppearance tp = cb.createAppearance(width, height); tp.setFontAndSize(font.getFontDescription().getFont(), fontSize); FSColor color = box.getStyle().getColor(); setFillColor(tp, color); field.setDefaultAppearanceString(tp); }
private void createAppearance( RenderingContext c, ITextOutputDevice outputDevice, BlockBox box, PdfFormField field) { PdfWriter writer = outputDevice.getWriter(); ITextFSFont font = (ITextFSFont)box.getStyle().getFSFont(c); PdfContentByte cb = writer.getDirectContent(); float width = outputDevice.getDeviceLength(getWidth()); float height = outputDevice.getDeviceLength(getHeight()); float fontSize = outputDevice.getDeviceLength(font.getSize2D()); PdfAppearance tp = cb.createAppearance(width, height); tp.setFontAndSize(font.getFontDescription().getFont(), fontSize); FSColor color = box.getStyle().getColor(); setFillColor(tp, color); field.setDefaultAppearanceString(tp); }
private void createAppearance( RenderingContext c, ITextOutputDevice outputDevice, BlockBox box, PdfFormField field) { PdfWriter writer = outputDevice.getWriter(); ITextFSFont font = (ITextFSFont)box.getStyle().getFSFont(c); PdfContentByte cb = writer.getDirectContent(); float width = outputDevice.getDeviceLength(getWidth()); float height = outputDevice.getDeviceLength(getHeight()); float fontSize = outputDevice.getDeviceLength(font.getSize2D()); PdfAppearance tp = cb.createAppearance(width, height); tp.setFontAndSize(font.getFontDescription().getFont(), fontSize); FSColor color = box.getStyle().getColor(); setFillColor(tp, color); field.setDefaultAppearanceString(tp); }
private void createAppearance( RenderingContext c, ITextOutputDevice outputDevice, BlockBox box, PdfFormField field) { PdfWriter writer = outputDevice.getWriter(); ITextFSFont font = (ITextFSFont)box.getStyle().getFSFont(c); PdfContentByte cb = writer.getDirectContent(); float width = outputDevice.getDeviceLength(getWidth()); float height = outputDevice.getDeviceLength(getHeight()); float fontSize = outputDevice.getDeviceLength(font.getSize2D()); PdfAppearance tp = cb.createAppearance(width, height); tp.setFontAndSize(font.getFontDescription().getFont(), fontSize); FSColor color = box.getStyle().getColor(); setFillColor(tp, color); field.setDefaultAppearanceString(tp); }
private void createAppearance( RenderingContext c, ITextOutputDevice outputDevice, BlockBox box, PdfFormField field) { PdfWriter writer = outputDevice.getWriter(); ITextFSFont font = (ITextFSFont)box.getStyle().getFSFont(c); PdfContentByte cb = writer.getDirectContent(); float width = outputDevice.getDeviceLength(getWidth()); float height = outputDevice.getDeviceLength(getHeight()); float fontSize = outputDevice.getDeviceLength(font.getSize2D()); PdfAppearance tp = cb.createAppearance(width, height); tp.setFontAndSize(font.getFontDescription().getFont(), fontSize); FSColor color = box.getStyle().getColor(); setFillColor(tp, color); field.setDefaultAppearanceString(tp); }
protected void drawHyperlink( final RenderNode box, final String target, final String window, final String title ) { if ( box.isNodeVisible( getDrawArea() ) == false ) { return; } final PdfAction action = createActionForLink( target ); final AffineTransform affineTransform = getGraphics().getTransform(); final float translateX = (float) affineTransform.getTranslateX(); final float leftX = translateX + (float) ( StrictGeomUtility.toExternalValue( box.getX() ) ); final float rightX = translateX + (float) ( StrictGeomUtility.toExternalValue( box.getX() + box.getWidth() ) ); final float lowerY = (float) ( globalHeight - StrictGeomUtility.toExternalValue( box.getY() + box.getHeight() ) ); final float upperY = (float) ( globalHeight - StrictGeomUtility.toExternalValue( box.getY() ) ); if ( action != null ) { final PdfAnnotation annotation = new PdfAnnotation( writer, leftX, lowerY, rightX, upperY, action ); writer.addAnnotation( annotation ); } else if ( StringUtils.isEmpty( title ) == false ) { final Rectangle rect = new Rectangle( leftX, lowerY, rightX, upperY ); final PdfAnnotation commentAnnotation = PdfAnnotation.createText( writer, rect, "Tooltip", title, false, null ); commentAnnotation.setAppearance( PdfAnnotation.APPEARANCE_NORMAL, writer.getDirectContent().createAppearance( rect.getWidth(), rect.getHeight() ) ); writer.addAnnotation( commentAnnotation ); } }
float fontSize = outputDevice.getDeviceLength(font.getSize2D()); PdfAppearance tp = cb.createAppearance(width, height); PdfAppearance tp2 = (PdfAppearance)tp.getDuplicate(); tp2.setFontAndSize(font.getFontDescription().getFont(), fontSize);
float fontSize = outputDevice.getDeviceLength(font.getSize2D()); PdfAppearance tp = cb.createAppearance(width, height); PdfAppearance tp2 = (PdfAppearance)tp.getDuplicate(); tp2.setFontAndSize(font.getFontDescription().getFont(), fontSize);
private void createAppearance(RenderingContext c, ITextOutputDevice outputDevice, BlockBox box, PdfFormField field, String value) { PdfWriter writer = outputDevice.getWriter(); ITextFSFont font = (ITextFSFont) box.getStyle().getFSFont(c); PdfContentByte cb = writer.getDirectContent(); float width = outputDevice.getDeviceLength(getWidth()); float height = outputDevice.getDeviceLength(getHeight()); float fontSize = outputDevice.getDeviceLength(font.getSize2D()); PdfAppearance tp = cb.createAppearance(width, height); PdfAppearance tp2 = (PdfAppearance) tp.getDuplicate(); tp2.setFontAndSize(font.getFontDescription().getFont(), fontSize); FSColor color = box.getStyle().getColor(); setFillColor(tp2, color); field.setDefaultAppearanceString(tp2); tp.beginVariableText(); tp.saveState(); tp.beginText(); tp.setFontAndSize(font.getFontDescription().getFont(), fontSize); setFillColor(tp, color); tp.setTextMatrix(0, height / 2 - (fontSize * 0.3f)); tp.showText(value); tp.endText(); tp.restoreState(); tp.endVariableText(); field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp); }
private void createAppearance(RenderingContext c, ITextOutputDevice outputDevice, BlockBox box, PdfFormField field, String value) { PdfWriter writer = outputDevice.getWriter(); ITextFSFont font = (ITextFSFont) box.getStyle().getFSFont(c); PdfContentByte cb = writer.getDirectContent(); float width = outputDevice.getDeviceLength(getWidth()); float height = outputDevice.getDeviceLength(getHeight()); float fontSize = outputDevice.getDeviceLength(font.getSize2D()); PdfAppearance tp = cb.createAppearance(width, height); PdfAppearance tp2 = (PdfAppearance) tp.getDuplicate(); tp2.setFontAndSize(font.getFontDescription().getFont(), fontSize); FSColor color = box.getStyle().getColor(); setFillColor(tp2, color); field.setDefaultAppearanceString(tp2); tp.beginVariableText(); tp.saveState(); tp.beginText(); tp.setFontAndSize(font.getFontDescription().getFont(), fontSize); setFillColor(tp, color); tp.setTextMatrix(0, height / 2 - (fontSize * 0.3f)); tp.showText(value); tp.endText(); tp.restoreState(); tp.endVariableText(); field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp); }
float fontSize = outputDevice.getDeviceLength(font.getSize2D()); PdfAppearance tp = cb.createAppearance(width, height); PdfAppearance tp2 = (PdfAppearance)tp.getDuplicate(); tp2.setFontAndSize(font.getFontDescription().getFont(), fontSize);