public class PushbuttonField extends BaseField
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();
Modifier and Type | Field and Description |
---|---|
static int |
LAYOUT_ICON_LEFT_LABEL_RIGHT
A layout option
|
static int |
LAYOUT_ICON_ONLY
A layout option
|
static int |
LAYOUT_ICON_TOP_LABEL_BOTTOM
A layout option
|
static int |
LAYOUT_LABEL_LEFT_ICON_RIGHT
A layout option
|
static int |
LAYOUT_LABEL_ONLY
A layout option
|
static int |
LAYOUT_LABEL_OVER_ICON
A layout option
|
static int |
LAYOUT_LABEL_TOP_ICON_BOTTOM
A layout option
|
static int |
SCALE_ICON_ALWAYS
An icon scaling option
|
static int |
SCALE_ICON_IS_TOO_BIG
An icon scaling option
|
static int |
SCALE_ICON_IS_TOO_SMALL
An icon scaling option
|
static int |
SCALE_ICON_NEVER
An icon scaling option
|
alignment, backgroundColor, BORDER_WIDTH_MEDIUM, BORDER_WIDTH_THICK, BORDER_WIDTH_THIN, borderColor, borderStyle, borderWidth, box, COMB, DO_NOT_SCROLL, DO_NOT_SPELL_CHECK, EDIT, fieldName, FILE_SELECTION, font, fontSize, HIDDEN, HIDDEN_BUT_PRINTABLE, maxCharacterLength, MULTILINE, MULTISELECT, options, PASSWORD, READ_ONLY, REQUIRED, rotation, text, textColor, visibility, VISIBLE, VISIBLE_BUT_DOES_NOT_PRINT, writer
Constructor and Description |
---|
PushbuttonField(PdfWriter writer, Rectangle box, String fieldName)
Creates a new instance of PushbuttonField
|
Modifier and Type | Method and Description |
---|---|
PdfAppearance |
getAppearance()
Gets the button appearance.
|
PdfFormField |
getField()
Gets the pushbutton field.
|
float |
getIconHorizontalAdjustment()
Getter for property iconHorizontalAdjustment.
|
PRIndirectReference |
getIconReference()
Gets the reference to an existing icon.
|
float |
getIconVerticalAdjustment()
Getter for property iconVerticalAdjustment.
|
Image |
getImage()
Getter for property image.
|
int |
getLayout()
Getter for property layout.
|
int |
getScaleIcon()
Getter for property scaleIcon.
|
PdfTemplate |
getTemplate()
Getter for property template.
|
boolean |
isIconFitToBounds()
Getter for property iconFitToBounds.
|
boolean |
isProportionalIcon()
Getter for property proportionalIcon.
|
void |
setIconFitToBounds(boolean iconFitToBounds)
If true the icon will be scaled to fit fully within the bounds of the annotation, if false the border width will be taken into account.
|
void |
setIconHorizontalAdjustment(float iconHorizontalAdjustment)
A number between 0 and 1 indicating the fraction of leftover space to allocate at the left of the icon.
|
void |
setIconReference(PRIndirectReference iconReference)
Sets the reference to an existing icon.
|
void |
setIconVerticalAdjustment(float iconVerticalAdjustment)
A number between 0 and 1 indicating the fraction of leftover space to allocate at the bottom of the icon.
|
void |
setImage(Image image)
Sets the icon as an image.
|
void |
setLayout(int layout)
Sets the icon and label layout.
|
void |
setProportionalIcon(boolean proportionalIcon)
Sets the way the icon is scaled.
|
void |
setScaleIcon(int scaleIcon)
Sets the way the icon will be scaled.
|
void |
setTemplate(PdfTemplate template)
Sets the icon as a template.
|
breakLines, getAlignment, getBackgroundColor, getBorderAppearance, getBorderColor, getBorderStyle, getBorderWidth, getBox, getFieldName, getFont, getFontSize, getHardBreaks, getMaxCharacterLength, getOptions, getRealFont, getRotation, getText, getTextColor, getVisibility, getWriter, moveFields, setAlignment, setBackgroundColor, setBorderColor, setBorderStyle, setBorderWidth, setBox, setFieldName, setFont, setFontSize, setMaxCharacterLength, setOptions, setRotation, setRotationFromPage, setText, setTextColor, setVisibility, setWriter, trimRight
public static final int LAYOUT_LABEL_ONLY
public static final int LAYOUT_ICON_ONLY
public static final int LAYOUT_ICON_TOP_LABEL_BOTTOM
public static final int LAYOUT_LABEL_TOP_ICON_BOTTOM
public static final int LAYOUT_ICON_LEFT_LABEL_RIGHT
public static final int LAYOUT_LABEL_LEFT_ICON_RIGHT
public static final int LAYOUT_LABEL_OVER_ICON
public static final int SCALE_ICON_ALWAYS
public static final int SCALE_ICON_NEVER
public static final int SCALE_ICON_IS_TOO_BIG
public static final int SCALE_ICON_IS_TOO_SMALL
public PushbuttonField(PdfWriter writer, Rectangle box, String fieldName)
writer
- the document PdfWriter
box
- the field location and dimensions
fieldName
- the field name. If null
only the widget keys will be included in the field allowing it to be used as a kid field.
public int getLayout()
public void setLayout(int layout)
LAYOUT_LABEL_ONLY
, LAYOUT_ICON_ONLY
, LAYOUT_ICON_TOP_LABEL_BOTTOM
, LAYOUT_LABEL_TOP_ICON_BOTTOM
, LAYOUT_ICON_LEFT_LABEL_RIGHT
, LAYOUT_LABEL_LEFT_ICON_RIGHT
and LAYOUT_LABEL_OVER_ICON
. The default is LAYOUT_LABEL_ONLY
.
layout
- New value of property layout.
public Image getImage()
public void setImage(Image image)
image
- the image
public PdfTemplate getTemplate()
public void setTemplate(PdfTemplate template)
template
- the template
public int getScaleIcon()
public void setScaleIcon(int scaleIcon)
SCALE_ICON_ALWAYS
, SCALE_ICON_NEVER
, SCALE_ICON_IS_TOO_BIG
and SCALE_ICON_IS_TOO_SMALL
. The default is SCALE_ICON_ALWAYS
.
scaleIcon
- the way the icon will be scaled
public boolean isProportionalIcon()
public void setProportionalIcon(boolean proportionalIcon)
true
the icon is scaled proportionally, if false
the scaling is done anamorphicaly.
proportionalIcon
- the way the icon is scaled
public float getIconVerticalAdjustment()
public void setIconVerticalAdjustment(float iconVerticalAdjustment)
iconVerticalAdjustment
- a number between 0 and 1 indicating the fraction of leftover space to allocate at the bottom of the icon
public float getIconHorizontalAdjustment()
public void setIconHorizontalAdjustment(float iconHorizontalAdjustment)
iconHorizontalAdjustment
- a number between 0 and 1 indicating the fraction of leftover space to allocate at the left of the icon
public PdfAppearance getAppearance() throws IOException, DocumentException
IOException
- on error
DocumentException
- on error
public PdfFormField getField() throws IOException, DocumentException
IOException
- on error
DocumentException
- on error
public boolean isIconFitToBounds()
public void setIconFitToBounds(boolean iconFitToBounds)
true
the icon will be scaled to fit fully within the bounds of the annotation, if false
the border width will be taken into account. The default is false
.
iconFitToBounds
- if true
the icon will be scaled to fit fully within the bounds of the annotation, if false
the border width will be taken into account
public PRIndirectReference getIconReference()
public void setIconReference(PRIndirectReference iconReference)
iconReference
- the reference to an existing icon
Copyright © 1998–2016. All rights reserved.