use of org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceEntry in project pdfbox by apache.
the class PDCheckBox method getOnValue.
/**
* Get the value which sets the check box to the On state.
*
* <p>The On value should be 'Yes' but other values are possible
* so we need to look for that. On the other hand the Off value shall
* always be 'Off'. If not set or not part of the normal appearance keys
* 'Off' is the default</p>
*
* @return the value setting the check box to the On state.
* If an empty string is returned there is no appearance definition.
*/
public String getOnValue() {
PDAnnotationWidget widget = this.getWidgets().get(0);
PDAppearanceDictionary apDictionary = widget.getAppearance();
String onValue = "";
if (apDictionary != null) {
PDAppearanceEntry normalAppearance = apDictionary.getNormalAppearance();
if (normalAppearance != null) {
Set<COSName> entries = normalAppearance.getSubDictionary().keySet();
for (COSName entry : entries) {
if (COSName.Off.compareTo(entry) != 0) {
onValue = entry.getName();
}
}
}
}
return onValue;
}
use of org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceEntry in project pdfbox by apache.
the class PDAbstractAppearanceHandler method getDownAppearance.
/**
* Get the annotations down appearance.
*
* <p>
* This will get the annotations down appearance. If this is not existent an
* empty appearance entry will be created.
*
* @return the appearance entry representing the down appearance.
*/
PDAppearanceEntry getDownAppearance() {
PDAppearanceDictionary appearanceDictionary = getAppearance();
PDAppearanceEntry downAppearanceEntry = appearanceDictionary.getDownAppearance();
if (downAppearanceEntry.isSubDictionary()) {
// TODO replace with "document.getDocument().createCOSStream()"
downAppearanceEntry = new PDAppearanceEntry(new COSStream());
appearanceDictionary.setDownAppearance(downAppearanceEntry);
}
return downAppearanceEntry;
}
use of org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceEntry in project pdfbox by apache.
the class PDAbstractAppearanceHandler method getRolloverAppearance.
/**
* Get the annotations rollover appearance.
*
* <p>
* This will get the annotations rollover appearance. If this is not
* existent an empty appearance entry will be created.
*
* @return the appearance entry representing the rollover appearance.
*/
PDAppearanceEntry getRolloverAppearance() {
PDAppearanceDictionary appearanceDictionary = getAppearance();
PDAppearanceEntry rolloverAppearanceEntry = appearanceDictionary.getRolloverAppearance();
if (rolloverAppearanceEntry.isSubDictionary()) {
// TODO replace with "document.getDocument().createCOSStream()"
rolloverAppearanceEntry = new PDAppearanceEntry(new COSStream());
appearanceDictionary.setRolloverAppearance(rolloverAppearanceEntry);
}
return rolloverAppearanceEntry;
}
use of org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceEntry in project pdfbox by apache.
the class PDAbstractAppearanceHandler method getNormalAppearance.
/**
* Get the annotations normal appearance.
*
* <p>
* This will get the annotations normal appearance. If this is not existent
* an empty appearance entry will be created.
*
* @return the appearance entry representing the normal appearance.
*/
private PDAppearanceEntry getNormalAppearance() {
PDAppearanceDictionary appearanceDictionary = getAppearance();
PDAppearanceEntry normalAappearanceEntry = appearanceDictionary.getNormalAppearance();
if (normalAappearanceEntry.isSubDictionary()) {
// TODO replace with "document.getDocument().createCOSStream()"
normalAappearanceEntry = new PDAppearanceEntry(new COSStream());
appearanceDictionary.setNormalAppearance(normalAappearanceEntry);
}
return normalAappearanceEntry;
}
use of org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceEntry in project pdfbox by apache.
the class AppearanceGeneratorHelper method setAppearanceValue.
/**
* This is the public method for setting the appearance stream.
*
* @param apValue the String value which the appearance should represent
* @throws IOException If there is an error creating the stream.
*/
public void setAppearanceValue(String apValue) throws IOException {
value = apValue;
// see PDFBOX-3911
if (field instanceof PDTextField && !((PDTextField) field).isMultiline()) {
value = apValue.replaceAll("\\u000D\\u000A|[\\u000A\\u000B\\u000C\\u000D\\u0085\\u2028\\u2029]", " ");
}
for (PDAnnotationWidget widget : field.getWidgets()) {
// some fields have the /Da at the widget level if the
// widgets differ in layout.
PDDefaultAppearanceString acroFormAppearance = defaultAppearance;
if (widget.getCOSObject().getDictionaryObject(COSName.DA) != null) {
defaultAppearance = getWidgetDefaultAppearanceString(widget);
}
PDRectangle rect = widget.getRectangle();
if (rect == null) {
widget.getCOSObject().removeItem(COSName.AP);
LOG.warn("widget of field " + field.getFullyQualifiedName() + " has no rectangle, no appearance stream created");
continue;
}
PDFormFieldAdditionalActions actions = field.getActions();
// when it is opened. See FreedomExpressions.pdf for an example of this.
if (actions == null || actions.getF() == null || widget.getCOSObject().getDictionaryObject(COSName.AP) != null) {
PDAppearanceDictionary appearanceDict = widget.getAppearance();
if (appearanceDict == null) {
appearanceDict = new PDAppearanceDictionary();
widget.setAppearance(appearanceDict);
}
PDAppearanceEntry appearance = appearanceDict.getNormalAppearance();
// TODO support appearances other than "normal"
PDAppearanceStream appearanceStream;
if (appearance != null && appearance.isStream()) {
appearanceStream = appearance.getAppearanceStream();
} else {
appearanceStream = new PDAppearanceStream(field.getAcroForm().getDocument());
// Calculate the entries for the bounding box and the transformation matrix
// settings for the appearance stream
int rotation = resolveRotation(widget);
Matrix matrix = Matrix.getRotateInstance(Math.toRadians(rotation), 0, 0);
Point2D.Float point2D = matrix.transformPoint(rect.getWidth(), rect.getHeight());
PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), Math.abs((float) point2D.getY()));
appearanceStream.setBBox(bbox);
appearanceStream.setMatrix(calculateMatrix(bbox, rotation));
appearanceStream.setFormType(1);
appearanceStream.setResources(new PDResources());
appearanceDict.setNormalAppearance(appearanceStream);
// TODO support appearances other than "normal"
}
/*
* Adobe Acrobat always recreates the complete appearance stream if there is an appearance characteristics
* entry (the widget dictionaries MK entry). In addition if there is no content yet also create the appearance
* stream from the entries.
*
*/
if (widget.getAppearanceCharacteristics() != null || appearanceStream.getContentStream().getLength() == 0) {
initializeAppearanceContent(widget, appearanceStream);
}
setAppearanceContent(widget, appearanceStream);
}
// restore the field level appearance
defaultAppearance = acroFormAppearance;
}
}
Aggregations