Search in sources :

Example 6 with COSName

use of com.tom_roush.pdfbox.cos.COSName 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)

Example 7 with COSName

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

the class TestOptionalContentGroups method testOCGConsumption.

/**
 * Tests OCG functions on a loaded PDF.
 * @throws Exception if an error occurs
 */
public void testOCGConsumption() throws Exception {
    File pdfFile = new File(testResultsDir, "ocg-generation.pdf");
    if (!pdfFile.exists()) {
        testOCGGeneration();
    }
    PDDocument doc = PDDocument.load(pdfFile);
    try {
        assertEquals(1.5f, doc.getVersion());
        PDDocumentCatalog catalog = doc.getDocumentCatalog();
        PDPage page = doc.getPage(0);
        PDResources resources = page.getResources();
        COSName mc0 = COSName.getPDFName("oc1");
        PDOptionalContentGroup ocg = (PDOptionalContentGroup) resources.getProperties(mc0);
        assertNotNull(ocg);
        assertEquals("background", ocg.getName());
        assertNull(resources.getProperties(COSName.getPDFName("inexistent")));
        PDOptionalContentProperties ocgs = catalog.getOCProperties();
        assertEquals(BaseState.ON, ocgs.getBaseState());
        Set<String> names = new java.util.HashSet<String>(Arrays.asList(ocgs.getGroupNames()));
        assertEquals(3, names.size());
        assertTrue(names.contains("background"));
        assertTrue(ocgs.isGroupEnabled("background"));
        assertTrue(ocgs.isGroupEnabled("enabled"));
        assertFalse(ocgs.isGroupEnabled("disabled"));
        ocgs.setGroupEnabled("background", false);
        assertFalse(ocgs.isGroupEnabled("background"));
        PDOptionalContentGroup background = ocgs.getGroup("background");
        assertEquals(ocg.getName(), background.getName());
        assertNull(ocgs.getGroup("inexistent"));
        Collection<PDOptionalContentGroup> coll = ocgs.getOptionalContentGroups();
        assertEquals(3, coll.size());
        Set<String> nameSet = new HashSet<String>();
        for (PDOptionalContentGroup ocg2 : coll) {
            nameSet.add(ocg2.getName());
        }
        assertTrue(nameSet.contains("background"));
        assertTrue(nameSet.contains("enabled"));
        assertTrue(nameSet.contains("disabled"));
    } finally {
        doc.close();
    }
}
Also used : PDPage(com.tom_roush.pdfbox.pdmodel.PDPage) PDResources(com.tom_roush.pdfbox.pdmodel.PDResources) PDDocumentCatalog(com.tom_roush.pdfbox.pdmodel.PDDocumentCatalog) COSName(com.tom_roush.pdfbox.cos.COSName) PDDocument(com.tom_roush.pdfbox.pdmodel.PDDocument) File(java.io.File) HashSet(java.util.HashSet)

Example 8 with COSName

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

the class CryptFilter method encode.

@Override
protected void encode(InputStream input, OutputStream encoded, COSDictionary parameters) throws IOException {
    COSName encryptionName = (COSName) parameters.getDictionaryObject(COSName.NAME);
    if (encryptionName == null || encryptionName.equals(COSName.IDENTITY)) {
        // currently the only supported implementation is the Identity crypt filter
        Filter identityFilter = new IdentityFilter();
        identityFilter.encode(input, encoded, parameters);
    } else {
        throw new IOException("Unsupported crypt filter " + encryptionName.getName());
    }
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) IOException(java.io.IOException)

Example 9 with COSName

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

the class Filter method getDecodeParams.

// gets the decode params for a specific filter index, this is used to
// normalise the DecodeParams entry so that it is always a dictionary
protected COSDictionary getDecodeParams(COSDictionary dictionary, int index) {
    COSBase filter = dictionary.getDictionaryObject(COSName.FILTER, COSName.F);
    COSBase obj = dictionary.getDictionaryObject(COSName.DECODE_PARMS, COSName.DP);
    if (filter instanceof COSName && obj instanceof COSDictionary) {
        // but tests show that Adobe means "one filter name object".
        return (COSDictionary) obj;
    } else if (filter instanceof COSArray && obj instanceof COSArray) {
        COSArray array = (COSArray) obj;
        if (index < array.size()) {
            COSBase objAtIndex = array.getObject(index);
            if (objAtIndex instanceof COSDictionary) {
                return (COSDictionary) array.getObject(index);
            }
        }
    } else if (obj != null && !(filter instanceof COSArray || obj instanceof COSArray)) {
        Log.e("PdfBox-Android", "Expected DecodeParams to be an Array or Dictionary but found " + obj.getClass().getName());
    }
    return new COSDictionary();
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 10 with COSName

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

the class BeginMarkedContentSequence method process.

@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
    COSName tag = null;
    for (COSBase argument : arguments) {
        if (argument instanceof COSName) {
            tag = (COSName) argument;
        }
    }
    context.beginMarkedContentSequence(tag, null);
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Aggregations

COSName (com.tom_roush.pdfbox.cos.COSName)83 COSBase (com.tom_roush.pdfbox.cos.COSBase)50 COSArray (com.tom_roush.pdfbox.cos.COSArray)27 IOException (java.io.IOException)24 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)23 COSObject (com.tom_roush.pdfbox.cos.COSObject)11 COSString (com.tom_roush.pdfbox.cos.COSString)11 HashMap (java.util.HashMap)10 Map (java.util.Map)10 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)9 COSStream (com.tom_roush.pdfbox.cos.COSStream)7 PDFormXObject (com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject)7 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)5 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)5 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)5 PDXObject (com.tom_roush.pdfbox.pdmodel.graphics.PDXObject)5 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)4 PDTransparencyGroup (com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup)4 OutputStream (java.io.OutputStream)4 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)3