Search in sources :

Example 26 with COSBase

use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.

the class PDPolygonAppearanceHandler method getLineWidth.

/**
 * Get the line with of the border.
 *
 * Get the width of the line used to draw a border around the annotation.
 * This may either be specified by the annotation dictionaries Border
 * setting or by the W entry in the BS border style dictionary. If both are
 * missing the default width is 1.
 *
 * @return the line width
 */
// TODO: according to the PDF spec the use of the BS entry is annotation
// specific
// so we will leave that to be implemented by individual handlers.
// If at the end all annotations support the BS entry this can be handled
// here and removed from the individual handlers.
float getLineWidth() {
    PDAnnotationMarkup annotation = (PDAnnotationMarkup) getAnnotation();
    PDBorderStyleDictionary bs = annotation.getBorderStyle();
    if (bs != null) {
        return bs.getWidth();
    }
    COSArray borderCharacteristics = annotation.getBorder();
    if (borderCharacteristics.size() >= 3) {
        COSBase base = borderCharacteristics.getObject(2);
        if (base instanceof COSNumber) {
            return ((COSNumber) base).floatValue();
        }
    }
    return 1;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) PDAnnotationMarkup(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationMarkup) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDBorderStyleDictionary(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary)

Example 27 with COSBase

use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.

the class PDPolylineAppearanceHandler method getLineWidth.

// TODO DRY, this code is from polygonAppearanceHandler so it's double
/**
 * Get the line with of the border.
 *
 * Get the width of the line used to draw a border around the annotation.
 * This may either be specified by the annotation dictionaries Border
 * setting or by the W entry in the BS border style dictionary. If both are
 * missing the default width is 1.
 *
 * @return the line width
 */
// TODO: according to the PDF spec the use of the BS entry is annotation
// specific
// so we will leave that to be implemented by individual handlers.
// If at the end all annotations support the BS entry this can be handled
// here and removed from the individual handlers.
float getLineWidth() {
    PDAnnotationMarkup annotation = (PDAnnotationMarkup) getAnnotation();
    PDBorderStyleDictionary bs = annotation.getBorderStyle();
    if (bs != null) {
        return bs.getWidth();
    }
    COSArray borderCharacteristics = annotation.getBorder();
    if (borderCharacteristics.size() >= 3) {
        COSBase base = borderCharacteristics.getObject(2);
        if (base instanceof COSNumber) {
            return ((COSNumber) base).floatValue();
        }
    }
    return 1;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) PDAnnotationMarkup(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationMarkup) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDBorderStyleDictionary(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary)

Example 28 with COSBase

use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.

the class PDSquareAppearanceHandler method getLineWidth.

/**
 * Get the line with of the border.
 *
 * Get the width of the line used to draw a border around the annotation.
 * This may either be specified by the annotation dictionaries Border
 * setting or by the W entry in the BS border style dictionary. If both are
 * missing the default width is 1.
 *
 * @return the line width
 */
// TODO: according to the PDF spec the use of the BS entry is annotation
// specific
// so we will leave that to be implemented by individual handlers.
// If at the end all annotations support the BS entry this can be handled
// here and removed from the individual handlers.
float getLineWidth() {
    PDAnnotationMarkup annotation = (PDAnnotationMarkup) getAnnotation();
    PDBorderStyleDictionary bs = annotation.getBorderStyle();
    if (bs != null) {
        return bs.getWidth();
    }
    COSArray borderCharacteristics = annotation.getBorder();
    if (borderCharacteristics.size() >= 3) {
        COSBase base = borderCharacteristics.getObject(2);
        if (base instanceof COSNumber) {
            return ((COSNumber) base).floatValue();
        }
    }
    return 1;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) PDAnnotationMarkup(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationMarkup) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDBorderStyleDictionary(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary)

Example 29 with COSBase

use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.

the class PDPropBuildDataDict method setOS.

/**
 * Indicates the operating system. The string format isn't specified yet. Value will be stored
 * as first item of the array, as specified in PDF Signature Build Dictionary Specification for
 * PDF v1.7.
 *
 * @param os is a string with the system id or name.
 */
public void setOS(String os) {
    if (os == null) {
        dictionary.removeItem(COSName.OS);
    } else {
        COSBase osArray = dictionary.getItem(COSName.OS);
        if (!(osArray instanceof COSArray)) {
            osArray = new COSArray();
            osArray.setDirect(true);
            dictionary.setItem(COSName.OS, osArray);
        }
        ((COSArray) osArray).add(0, COSName.getPDFName(os));
    }
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 30 with COSBase

use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.

the class PDSeedValueCertificate method getSubjectDN.

/**
 * Returns list of maps that contains subject distinguished names like [(cn: John Doe, o: Doe), (cn: John Smith)]
 * both keys are typically of the form 'cn', 'o', 'email', '2.5.4.43'; and values are text strings.
 *
 * @return a list of maps containing the subject distinguished names
 */
public List<Map<String, String>> getSubjectDN() {
    COSBase base = this.dictionary.getDictionaryObject(COSName.SUBJECT_DN);
    if (base instanceof COSArray) {
        COSArray cosArray = (COSArray) base;
        List subjectDNList = cosArray.toList();
        List<Map<String, String>> result = new LinkedList<Map<String, String>>();
        for (Object subjectDNItem : subjectDNList) {
            if (subjectDNItem instanceof COSDictionary) {
                COSDictionary subjectDNItemDict = (COSDictionary) subjectDNItem;
                Map<String, String> subjectDNMap = new HashMap<String, String>();
                for (COSName key : subjectDNItemDict.keySet()) {
                    subjectDNMap.put(key.getName(), subjectDNItemDict.getString(key));
                }
                result.add(subjectDNMap);
            }
        }
        return result;
    }
    return null;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSName(com.tom_roush.pdfbox.cos.COSName) HashMap(java.util.HashMap) COSBase(com.tom_roush.pdfbox.cos.COSBase) List(java.util.List) COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) LinkedList(java.util.LinkedList) COSString(com.tom_roush.pdfbox.cos.COSString) Map(java.util.Map) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList)

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