Package com.aowagie.text.pdf
Class PushbuttonField
- java.lang.Object
-
- com.aowagie.text.pdf.BaseField
-
- com.aowagie.text.pdf.PushbuttonField
-
class PushbuttonField extends BaseField
Creates a pushbutton field. It supports all the text and icon alignments. The icon may be an image or a template.Example usage:
Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("output.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); Image img = Image.getInstance("image.png"); PushbuttonField bt = new PushbuttonField(writer, new Rectangle(100, 100, 200, 200), "Button1"); bt.setText("My Caption"); bt.setFontSize(0); bt.setImage(img); bt.setLayout(PushbuttonField.LAYOUT_ICON_TOP_LABEL_BOTTOM); bt.setBackgroundColor(Color.cyan); bt.setBorderStyle(PdfBorderDictionary.STYLE_SOLID); bt.setBorderColor(Color.red); bt.setBorderWidth(3); PdfFormField ff = bt.getField(); PdfAction ac = PdfAction.createSubmitForm("http://www.submit-site.com", null, 0); ff.setAction(ac); writer.addAnnotation(ff); document.close();
-
-
Field Summary
Fields Modifier and Type Field Description private booleaniconFitToBoundsHolds value of property iconFitToBounds.private floaticonHorizontalAdjustmentHolds value of property iconHorizontalAdjustment.private PRIndirectReferenceiconReferenceHolds value of property iconReference.private floaticonVerticalAdjustmentHolds value of property iconVerticalAdjustment.private ImageimageHolds value of property image.private intlayoutHolds value of property layout.private static intLAYOUT_ICON_LEFT_LABEL_RIGHTA layout optionprivate static intLAYOUT_ICON_ONLYA layout optionprivate static intLAYOUT_ICON_TOP_LABEL_BOTTOMA layout optionprivate static intLAYOUT_LABEL_LEFT_ICON_RIGHTA layout optionprivate static intLAYOUT_LABEL_ONLYA layout optionprivate static intLAYOUT_LABEL_OVER_ICONA layout optionprivate static intLAYOUT_LABEL_TOP_ICON_BOTTOMA layout optionprivate booleanproportionalIconHolds value of property proportionalIcon.(package private) static intSCALE_ICON_ALWAYSAn icon scaling option(package private) static intSCALE_ICON_IS_TOO_BIGAn icon scaling option(package private) static intSCALE_ICON_IS_TOO_SMALLAn icon scaling option(package private) static intSCALE_ICON_NEVERAn icon scaling optionprivate intscaleIconHolds value of property scaleIcon.private PdfTemplatetemplateHolds value of property template.private PdfTemplatetp-
Fields inherited from class com.aowagie.text.pdf.BaseField
alignment, backgroundColor, borderColor, borderStyle, borderWidth, box, COMB, DO_NOT_SCROLL, DO_NOT_SPELL_CHECK, EDIT, fieldName, FILE_SELECTION, fontSize, HIDDEN, HIDDEN_BUT_PRINTABLE, maxCharacterLength, MULTILINE, options, PASSWORD, READ_ONLY, REQUIRED, rotation, text, textColor, visibility, VISIBLE, VISIBLE_BUT_DOES_NOT_PRINT, writer
-
-
Constructor Summary
Constructors Constructor Description PushbuttonField(PdfWriter writer, Rectangle box, java.lang.String fieldName)Creates a new instance of PushbuttonField
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private floatcalculateFontSize(float w, float h)PdfAppearancegetAppearance()Gets the button appearance.PdfFormFieldgetField()Gets the pushbutton field.floatgetIconHorizontalAdjustment()Getter for property iconHorizontalAdjustment.PRIndirectReferencegetIconReference()Gets the reference to an existing icon.floatgetIconVerticalAdjustment()Getter for property iconVerticalAdjustment.ImagegetImage()Getter for property image.intgetLayout()Getter for property layout.intgetScaleIcon()Getter for property scaleIcon.PdfTemplategetTemplate()Getter for property template.booleanisIconFitToBounds()Getter for property iconFitToBounds.booleanisProportionalIcon()Getter for property proportionalIcon.voidsetIconFitToBounds(boolean iconFitToBounds)Iftruethe icon will be scaled to fit fully within the bounds of the annotation, iffalsethe border width will be taken into account.voidsetIconHorizontalAdjustment(float iconHorizontalAdjustment)A number between 0 and 1 indicating the fraction of leftover space to allocate at the left of the icon.voidsetIconReference(PRIndirectReference iconReference)Sets the reference to an existing icon.voidsetIconVerticalAdjustment(float iconVerticalAdjustment)A number between 0 and 1 indicating the fraction of leftover space to allocate at the bottom of the icon.voidsetImage(Image image)Sets the icon as an image.voidsetLayout(int layout)Sets the icon and label layout.voidsetProportionalIcon(boolean proportionalIcon)Sets the way the icon is scaled.voidsetScaleIcon(int scaleIcon)Sets the way the icon will be scaled.voidsetTemplate(PdfTemplate template)Sets the icon as a template.-
Methods inherited from class com.aowagie.text.pdf.BaseField
getAlignment, getBackgroundColor, getBorderAppearance, getBorderColor, getBorderStyle, getBorderWidth, getBox, getFieldName, getFont, getFontSize, getMaxCharacterLength, getOptions, getRealFont, getRotation, getText, getTextColor, getVisibility, getWriter, setAlignment, setBackgroundColor, setBorderColor, setBorderStyle, setBorderWidth, setBox, setFieldName, setFont, setFontSize, setMaxCharacterLength, setOptions, setRotation, setRotationFromPage, setText, setTextColor, setVisibility, setWriter
-
-
-
-
Field Detail
-
LAYOUT_LABEL_ONLY
private static final int LAYOUT_LABEL_ONLY
A layout option- See Also:
- Constant Field Values
-
LAYOUT_ICON_ONLY
private static final int LAYOUT_ICON_ONLY
A layout option- See Also:
- Constant Field Values
-
LAYOUT_ICON_TOP_LABEL_BOTTOM
private static final int LAYOUT_ICON_TOP_LABEL_BOTTOM
A layout option- See Also:
- Constant Field Values
-
LAYOUT_LABEL_TOP_ICON_BOTTOM
private static final int LAYOUT_LABEL_TOP_ICON_BOTTOM
A layout option- See Also:
- Constant Field Values
-
LAYOUT_ICON_LEFT_LABEL_RIGHT
private static final int LAYOUT_ICON_LEFT_LABEL_RIGHT
A layout option- See Also:
- Constant Field Values
-
LAYOUT_LABEL_LEFT_ICON_RIGHT
private static final int LAYOUT_LABEL_LEFT_ICON_RIGHT
A layout option- See Also:
- Constant Field Values
-
LAYOUT_LABEL_OVER_ICON
private static final int LAYOUT_LABEL_OVER_ICON
A layout option- See Also:
- Constant Field Values
-
SCALE_ICON_ALWAYS
static final int SCALE_ICON_ALWAYS
An icon scaling option- See Also:
- Constant Field Values
-
SCALE_ICON_NEVER
static final int SCALE_ICON_NEVER
An icon scaling option- See Also:
- Constant Field Values
-
SCALE_ICON_IS_TOO_BIG
static final int SCALE_ICON_IS_TOO_BIG
An icon scaling option- See Also:
- Constant Field Values
-
SCALE_ICON_IS_TOO_SMALL
static final int SCALE_ICON_IS_TOO_SMALL
An icon scaling option- See Also:
- Constant Field Values
-
layout
private int layout
Holds value of property layout.
-
image
private Image image
Holds value of property image.
-
template
private PdfTemplate template
Holds value of property template.
-
scaleIcon
private int scaleIcon
Holds value of property scaleIcon.
-
proportionalIcon
private boolean proportionalIcon
Holds value of property proportionalIcon.
-
iconVerticalAdjustment
private float iconVerticalAdjustment
Holds value of property iconVerticalAdjustment.
-
iconHorizontalAdjustment
private float iconHorizontalAdjustment
Holds value of property iconHorizontalAdjustment.
-
iconFitToBounds
private boolean iconFitToBounds
Holds value of property iconFitToBounds.
-
tp
private PdfTemplate tp
-
iconReference
private PRIndirectReference iconReference
Holds value of property iconReference.
-
-
Constructor Detail
-
PushbuttonField
PushbuttonField(PdfWriter writer, Rectangle box, java.lang.String fieldName)
Creates a new instance of PushbuttonField- Parameters:
writer- the documentPdfWriterbox- the field location and dimensionsfieldName- the field name. Ifnullonly the widget keys will be included in the field allowing it to be used as a kid field.
-
-
Method Detail
-
getLayout
public int getLayout()
Getter for property layout.- Returns:
- Value of property layout.
-
setLayout
public void setLayout(int layout)
Sets the icon and label layout. Possible values areLAYOUT_LABEL_ONLY,LAYOUT_ICON_ONLY,LAYOUT_ICON_TOP_LABEL_BOTTOM,LAYOUT_LABEL_TOP_ICON_BOTTOM,LAYOUT_ICON_LEFT_LABEL_RIGHT,LAYOUT_LABEL_LEFT_ICON_RIGHTandLAYOUT_LABEL_OVER_ICON. The default isLAYOUT_LABEL_ONLY.- Parameters:
layout- New value of property layout.
-
getImage
public Image getImage()
Getter for property image.- Returns:
- Value of property image.
-
setImage
public void setImage(Image image)
Sets the icon as an image.- Parameters:
image- the image
-
getTemplate
public PdfTemplate getTemplate()
Getter for property template.- Returns:
- Value of property template.
-
setTemplate
public void setTemplate(PdfTemplate template)
Sets the icon as a template.- Parameters:
template- the template
-
getScaleIcon
public int getScaleIcon()
Getter for property scaleIcon.- Returns:
- Value of property scaleIcon.
-
setScaleIcon
public void setScaleIcon(int scaleIcon)
Sets the way the icon will be scaled. Possible values areSCALE_ICON_ALWAYS,SCALE_ICON_NEVER,SCALE_ICON_IS_TOO_BIGandSCALE_ICON_IS_TOO_SMALL. The default isSCALE_ICON_ALWAYS.- Parameters:
scaleIcon- the way the icon will be scaled
-
isProportionalIcon
public boolean isProportionalIcon()
Getter for property proportionalIcon.- Returns:
- Value of property proportionalIcon.
-
setProportionalIcon
public void setProportionalIcon(boolean proportionalIcon)
Sets the way the icon is scaled. Iftruethe icon is scaled proportionally, iffalsethe scaling is done anamorphicaly.- Parameters:
proportionalIcon- the way the icon is scaled
-
getIconVerticalAdjustment
public float getIconVerticalAdjustment()
Getter for property iconVerticalAdjustment.- Returns:
- Value of property iconVerticalAdjustment.
-
setIconVerticalAdjustment
public void setIconVerticalAdjustment(float iconVerticalAdjustment)
A number between 0 and 1 indicating the fraction of leftover space to allocate at the bottom of the icon. A value of 0 positions the icon at the bottom of the annotation rectangle. A value of 0.5 centers it within the rectangle. The default is 0.5.- Parameters:
iconVerticalAdjustment- a number between 0 and 1 indicating the fraction of leftover space to allocate at the bottom of the icon
-
getIconHorizontalAdjustment
public float getIconHorizontalAdjustment()
Getter for property iconHorizontalAdjustment.- Returns:
- Value of property iconHorizontalAdjustment.
-
setIconHorizontalAdjustment
public void setIconHorizontalAdjustment(float iconHorizontalAdjustment)
A number between 0 and 1 indicating the fraction of leftover space to allocate at the left of the icon. A value of 0 positions the icon at the left of the annotation rectangle. A value of 0.5 centers it within the rectangle. The default is 0.5.- Parameters:
iconHorizontalAdjustment- a number between 0 and 1 indicating the fraction of leftover space to allocate at the left of the icon
-
calculateFontSize
private float calculateFontSize(float w, float h) throws java.io.IOException, DocumentException- Throws:
java.io.IOExceptionDocumentException
-
getAppearance
public PdfAppearance getAppearance() throws java.io.IOException, DocumentException
Gets the button appearance.- Returns:
- the button appearance
- Throws:
java.io.IOException- on errorDocumentException- on error
-
getField
public PdfFormField getField() throws java.io.IOException, DocumentException
Gets the pushbutton field.- Returns:
- the pushbutton field
- Throws:
java.io.IOException- on errorDocumentException- on error
-
isIconFitToBounds
public boolean isIconFitToBounds()
Getter for property iconFitToBounds.- Returns:
- Value of property iconFitToBounds.
-
setIconFitToBounds
public void setIconFitToBounds(boolean iconFitToBounds)
Iftruethe icon will be scaled to fit fully within the bounds of the annotation, iffalsethe border width will be taken into account. The default isfalse.- Parameters:
iconFitToBounds- iftruethe icon will be scaled to fit fully within the bounds of the annotation, iffalsethe border width will be taken into account
-
getIconReference
public PRIndirectReference getIconReference()
Gets the reference to an existing icon.- Returns:
- the reference to an existing icon.
-
setIconReference
public void setIconReference(PRIndirectReference iconReference)
Sets the reference to an existing icon.- Parameters:
iconReference- the reference to an existing icon
-
-