use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.
the class PDButton method getExportValues.
/**
* This will get the (optional) export values.
*
* <p>The export values are defined in the field dictionaries /Opt key.</p>
*
* <p>The option values are used to define the export values
* for the field to
* <ul>
* <li>hold values in non-Latin writing systems as name objects, which represent the field value, are limited
* to PDFDocEncoding
* </li>
* <li>allow radio buttons having the same export value to be handled independently
* </li>
* </ul>
*
* @return List containing all possible export values. If there is no /Opt entry an empty list will be returned.
*
* @see #getOnValues()
*/
public List<String> getExportValues() {
COSBase value = getInheritableAttribute(COSName.OPT);
if (value instanceof COSString) {
List<String> array = new ArrayList<String>();
array.add(((COSString) value).getString());
return array;
} else if (value instanceof COSArray) {
return COSArrayList.convertCOSStringCOSArrayToList((COSArray) value);
}
return Collections.emptyList();
}
use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.
the class PDChoice method setOptions.
/**
* This will set the display and export values - the 'Opt' key.
*
* <p>
* This will set both, the export value and the display value
* of the choice field. If either one of the parameters is null or an
* empty list is supplied the options will
* be removed.
* </p>
* <p>
* An {@link IllegalArgumentException} will be thrown if the
* number of items in the list differ.
* </p>
*
* @see #setOptions(List)
* @param exportValues List containing all possible export values.
* @param displayValues List containing all possible display values.
*/
public void setOptions(List<String> exportValues, List<String> displayValues) {
if (exportValues != null && displayValues != null && !exportValues.isEmpty() && !displayValues.isEmpty()) {
if (exportValues.size() != displayValues.size()) {
throw new IllegalArgumentException("The number of entries for exportValue and displayValue shall be the same.");
} else {
List<KeyValue> keyValuePairs = FieldUtils.toKeyValueList(exportValues, displayValues);
if (isSort()) {
FieldUtils.sortByValue(keyValuePairs);
}
COSArray options = new COSArray();
for (int i = 0; i < exportValues.size(); i++) {
COSArray entry = new COSArray();
entry.add(new COSString(keyValuePairs.get(i).getKey()));
entry.add(new COSString(keyValuePairs.get(i).getValue()));
options.add(entry);
}
getCOSObject().setItem(COSName.OPT, options);
}
} else {
getCOSObject().removeItem(COSName.OPT);
}
}
use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.
the class FieldUtils method getPairableItems.
/**
* Return either one of a list which can have two-element arrays entries.
* <p>
* Some entries in a dictionary can either be an array of elements
* or an array of two-element arrays. This method will either return
* the elements in the array or in case of two-element arrays, the element
* designated by the pair index
* </p>
* <p>
* An {@link IllegalArgumentException} will be thrown if the items contain
* two-element arrays and the index is not 0 or 1.
* </p>
*
* @param items the array of elements or two-element arrays
* @param pairIdx the index into the two-element array
* @return a List of single elements
*/
static List<String> getPairableItems(COSBase items, int pairIdx) {
if (pairIdx < 0 || pairIdx > 1) {
throw new IllegalArgumentException("Only 0 and 1 are allowed as an index into two-element arrays");
}
if (items instanceof COSString) {
List<String> array = new ArrayList<String>();
array.add(((COSString) items).getString());
return array;
} else if (items instanceof COSArray) {
List<String> entryList = new ArrayList<String>();
for (COSBase entry : (COSArray) items) {
if (entry instanceof COSString) {
entryList.add(((COSString) entry).getString());
} else if (entry instanceof COSArray) {
COSArray cosArray = (COSArray) entry;
if (cosArray.size() >= pairIdx + 1 && cosArray.get(pairIdx) instanceof COSString) {
entryList.add(((COSString) cosArray.get(pairIdx)).getString());
}
}
}
return entryList;
}
return Collections.emptyList();
}
use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.
the class PDVariableText method getDefaultAppearanceString.
/**
* Get the default appearance.
*
* This is an inheritable attribute.
*
* The default appearance contains a set of default graphics and text operators
* to define the field’s text size and color.
*
* @return the DA element of the dictionary object
*/
PDDefaultAppearanceString getDefaultAppearanceString() throws IOException {
COSString da = (COSString) getInheritableAttribute(COSName.DA);
PDResources dr = getAcroForm().getDefaultResources();
return new PDDefaultAppearanceString(da, dr);
}
use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.
the class PDField method importFDF.
/**
* This will import a fdf field from a fdf document.
*
* @param fdfField The fdf field to import.
* @throws IOException If there is an error importing the data for this field.
*/
void importFDF(FDFField fdfField) throws IOException {
COSBase fieldValue = fdfField.getCOSValue();
if (fieldValue != null && this instanceof PDTerminalField) {
PDTerminalField currentField = (PDTerminalField) this;
if (fieldValue instanceof COSName) {
currentField.setValue(((COSName) fieldValue).getName());
} else if (fieldValue instanceof COSString) {
currentField.setValue(((COSString) fieldValue).getString());
} else if (fieldValue instanceof COSStream) {
currentField.setValue(((COSStream) fieldValue).toTextString());
} else if (fieldValue instanceof COSArray && this instanceof PDChoice) {
((PDChoice) this).setValue(COSArrayList.convertCOSStringCOSArrayToList((COSArray) fieldValue));
} else {
throw new IOException("Error:Unknown type for field import" + fieldValue);
}
} else if (fieldValue != null) {
dictionary.setItem(COSName.V, fieldValue);
}
Integer ff = fdfField.getFieldFlags();
if (ff != null) {
setFieldFlags(ff);
} else {
// these are suppose to be ignored if the Ff is set.
Integer setFf = fdfField.getSetFieldFlags();
int fieldFlags = getFieldFlags();
if (setFf != null) {
int setFfInt = setFf;
fieldFlags = fieldFlags | setFfInt;
setFieldFlags(fieldFlags);
}
Integer clrFf = fdfField.getClearFieldFlags();
if (clrFf != null) {
// we have to clear the bits of the document fields for every bit that is
// set in this field.
//
// Example:
// docFf = 1011
// clrFf = 1101
// clrFfValue = 0010;
// newValue = 1011 & 0010 which is 0010
int clrFfValue = clrFf;
clrFfValue ^= 0xFFFFFFFF;
fieldFlags = fieldFlags & clrFfValue;
setFieldFlags(fieldFlags);
}
}
}
Aggregations