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;
}
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();
}
}
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());
}
}
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();
}
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);
}
Aggregations