Search in sources :

Example 1 with PDAnnotationUnknown

use of com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationUnknown in project PdfBox-Android by TomRoush.

the class PageDrawer method showAnnotation.

@Override
public void showAnnotation(PDAnnotation annotation) throws IOException {
    lastClip = null;
    // Device checks shouldn't be needed
    if (annotation.isNoView()) {
        return;
    }
    if (annotation.isHidden()) {
        return;
    }
    if (annotation.isInvisible() && annotation instanceof PDAnnotationUnknown) {
        // of the standard annotation types and no annotation handler is available."
        return;
    }
    if (isHiddenOCG(annotation.getOptionalContent())) {
        return;
    }
    PDAppearanceDictionary appearance = annotation.getAppearance();
    if (appearance == null || appearance.getNormalAppearance() == null) {
        annotation.constructAppearances(renderer.document);
    }
    if (annotation.isNoRotate() && getCurrentPage().getRotation() != 0) {
        PDRectangle rect = annotation.getRectangle();
        android.graphics.Matrix savedTransform = canvas.getMatrix();
        // "The upper-left corner of the annotation remains at the same point in
        // default user space; the annotation pivots around that point."
        canvas.rotate(getCurrentPage().getRotation(), rect.getLowerLeftX(), rect.getUpperRightY());
        super.showAnnotation(annotation);
        canvas.setMatrix(savedTransform);
    } else {
        super.showAnnotation(annotation);
    }
}
Also used : PDAppearanceDictionary(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle) PDAnnotationUnknown(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationUnknown)

Example 2 with PDAnnotationUnknown

use of com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationUnknown in project PdfBox-Android by TomRoush.

the class PDObjectReference method getReferencedObject.

/**
 * Gets a higher-level object for the referenced object.
 * Currently this method may return a {@link PDAnnotation},
 * a {@link PDXObject} or <code>null</code>.
 *
 * @return a higher-level object for the referenced object
 */
public COSObjectable getReferencedObject() {
    COSBase obj = this.getCOSObject().getDictionaryObject(COSName.OBJ);
    if (!(obj instanceof COSDictionary)) {
        return null;
    }
    try {
        if (obj instanceof COSStream) {
            // <-- TODO: valid?
            PDXObject xobject = PDXObject.createXObject(obj, null);
            if (xobject != null) {
                return xobject;
            }
        }
        COSDictionary objDictionary = (COSDictionary) obj;
        PDAnnotation annotation = PDAnnotation.createAnnotation(obj);
        /*
             * COSName.TYPE is optional, so if annotation is of type unknown and
             * COSName.TYPE is not COSName.ANNOT it still may be an annotation.
             * TODO shall we return the annotation object instead of null?
             * what else can be the target of the object reference?
             */
        if (!(annotation instanceof PDAnnotationUnknown) || COSName.ANNOT.equals(objDictionary.getDictionaryObject(COSName.TYPE))) {
            return annotation;
        }
    } catch (IOException exception) {
    // this can only happen if the target is an XObject.
    }
    return null;
}
Also used : COSStream(com.tom_roush.pdfbox.cos.COSStream) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) PDAnnotation(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation) COSBase(com.tom_roush.pdfbox.cos.COSBase) IOException(java.io.IOException) PDAnnotationUnknown(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationUnknown) PDXObject(com.tom_roush.pdfbox.pdmodel.graphics.PDXObject)

Aggregations

PDAnnotationUnknown (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationUnknown)2 COSBase (com.tom_roush.pdfbox.cos.COSBase)1 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)1 COSStream (com.tom_roush.pdfbox.cos.COSStream)1 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)1 PDXObject (com.tom_roush.pdfbox.pdmodel.graphics.PDXObject)1 PDAnnotation (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation)1 PDAppearanceDictionary (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary)1 IOException (java.io.IOException)1