Search in sources :

Example 91 with COSBase

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);
        }
    }
}
Also used : COSStream(com.tom_roush.pdfbox.cos.COSStream) COSName(com.tom_roush.pdfbox.cos.COSName) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase) IOException(java.io.IOException) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 92 with COSBase

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);
}
Also used : PDPageAdditionalActions(com.tom_roush.pdfbox.pdmodel.interactive.action.PDPageAdditionalActions) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 93 with COSBase

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);
}
Also used : COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) COSArray(com.tom_roush.pdfbox.cos.COSArray) PDAnnotation(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation) ArrayList(java.util.ArrayList) COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 94 with COSBase

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;
}
Also used : COSStream(com.tom_roush.pdfbox.cos.COSStream) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDMetadata(com.tom_roush.pdfbox.pdmodel.common.PDMetadata)

Example 95 with COSBase

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;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Aggregations

COSBase (com.tom_roush.pdfbox.cos.COSBase)215 COSArray (com.tom_roush.pdfbox.cos.COSArray)108 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)68 COSName (com.tom_roush.pdfbox.cos.COSName)50 COSObject (com.tom_roush.pdfbox.cos.COSObject)42 IOException (java.io.IOException)34 COSString (com.tom_roush.pdfbox.cos.COSString)33 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)29 ArrayList (java.util.ArrayList)29 COSStream (com.tom_roush.pdfbox.cos.COSStream)20 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)14 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)11 HashMap (java.util.HashMap)11 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)10 Map (java.util.Map)10 List (java.util.List)9 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)8 COSFloat (com.tom_roush.pdfbox.cos.COSFloat)7 COSObjectKey (com.tom_roush.pdfbox.cos.COSObjectKey)7 PDFStreamParser (com.tom_roush.pdfbox.pdfparser.PDFStreamParser)6