use of com.tom_roush.pdfbox.cos.COSBase 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);
}
}
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDPage method getActions.
/**
* Get the page actions.
*
* @return The Actions for this Page
*/
public PDPageAdditionalActions getActions() {
COSDictionary addAct;
COSBase base = page.getDictionaryObject(COSName.AA);
if (base instanceof COSDictionary) {
addAct = (COSDictionary) base;
} else {
addAct = new COSDictionary();
page.setItem(COSName.AA, addAct);
}
return new PDPageAdditionalActions(addAct);
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDPage method getAnnotations.
/**
* This will return a list of the annotations for this page.
*
* @param annotationFilter the annotation filter provided allowing to filter out specific annotations
* @return List of the PDAnnotation objects, never null. The returned list is backed by the
* annotations COSArray, so any adding or deleting in this list will change the document too.
*
* @throws IOException If there is an error while creating the annotation list.
*/
public List<PDAnnotation> getAnnotations(AnnotationFilter annotationFilter) throws IOException {
COSBase base = page.getDictionaryObject(COSName.ANNOTS);
if (base instanceof COSArray) {
COSArray annots = (COSArray) base;
List<PDAnnotation> actuals = new ArrayList<PDAnnotation>();
for (int i = 0; i < annots.size(); i++) {
COSBase item = annots.getObject(i);
if (item == null) {
continue;
}
PDAnnotation createdAnnotation = PDAnnotation.createAnnotation(item);
if (annotationFilter.accept(createdAnnotation)) {
actuals.add(createdAnnotation);
}
}
return new COSArrayList<PDAnnotation>(actuals, annots);
}
return new COSArrayList<PDAnnotation>(page, COSName.ANNOTS);
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDPage method getMetadata.
/**
* Get the metadata that is part of the document catalog. This will return null if there is
* no meta data for this object.
*
* @return The metadata for this object.
*/
public PDMetadata getMetadata() {
PDMetadata retval = null;
COSBase base = page.getDictionaryObject(COSName.METADATA);
if (base instanceof COSStream) {
retval = new PDMetadata((COSStream) base);
}
return retval;
}
use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.
the class PDPage method getMediaBox.
/**
* A rectangle, expressed in default user space units, defining the boundaries of the physical medium on which the
* page is intended to be displayed or printed.
*
* @return the media box.
*/
public PDRectangle getMediaBox() {
if (mediaBox == null) {
COSBase base = PDPageTree.getInheritableAttribute(page, COSName.MEDIA_BOX);
if (base instanceof COSArray) {
mediaBox = new PDRectangle((COSArray) base);
}
}
if (mediaBox == null) {
Log.d("PdfBox-Android", "Can't find MediaBox, will use U.S. Letter");
mediaBox = PDRectangle.LETTER;
}
return mediaBox;
}
Aggregations