use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PDFontDescriptor method getFontStretch.
/**
* A string representing the preferred font stretch.
* According to the PDF Spec:
* The font stretch value; it must be one of the following (ordered from
* narrowest to widest): UltraCondensed, ExtraCondensed, Condensed, SemiCondensed,
* Normal, SemiExpanded, Expanded, ExtraExpanded or UltraExpanded.
*
* @return The stretch of the font.
*/
public String getFontStretch() {
String retval = null;
COSName name = (COSName) dic.getDictionaryObject(COSName.FONT_STRETCH);
if (name != null) {
retval = name.getName();
}
return retval;
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PageDrawer method isHiddenOCMD.
private boolean isHiddenOCMD(PDOptionalContentMembershipDictionary ocmd) {
if (ocmd.getCOSObject().getCOSArray(COSName.VE) != null) {
// support seems to be optional, and is approximated by /P and /OCGS
Log.i("PdfBox-Android", "/VE entry ignored in Optional Content Membership Dictionary");
}
List<Boolean> visibles = new ArrayList<Boolean>();
for (PDPropertyList prop : ocmd.getOCGs()) {
visibles.add(!isHiddenOCG(prop));
}
COSName visibilityPolicy = ocmd.getVisibilityPolicy();
if (COSName.ANY_OFF.equals(visibilityPolicy)) {
for (boolean visible : visibles) {
if (!visible) {
return true;
}
}
return false;
}
if (COSName.ALL_ON.equals(visibilityPolicy)) {
for (boolean visible : visibles) {
if (!visible) {
return true;
}
}
return false;
}
if (COSName.ALL_OFF.equals(visibilityPolicy)) {
for (boolean visible : visibles) {
if (visible) {
return false;
}
}
return true;
}
// AnyOn is default
for (boolean visible : visibles) {
if (visible) {
return false;
}
}
return true;
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PageDrawer method hasBlendMode.
private boolean hasBlendMode(PDTransparencyGroup group, Set<COSBase> groupsDone) {
if (groupsDone.contains(group.getCOSObject())) {
// The group was already processed. Avoid endless recursion.
return false;
}
groupsDone.add(group.getCOSObject());
PDResources resources = group.getResources();
if (resources == null) {
return false;
}
for (COSName name : resources.getExtGStateNames()) {
PDExtendedGraphicsState extGState = resources.getExtGState(name);
if (extGState == null) {
continue;
}
BlendMode blendMode = extGState.getBlendMode();
if (blendMode != BlendMode.NORMAL) {
return true;
}
}
// Recursively process nested transparency groups
for (COSName name : resources.getXObjectNames()) {
PDXObject xObject;
try {
xObject = resources.getXObject(name);
} catch (IOException ex) {
continue;
}
if (xObject instanceof PDTransparencyGroup && hasBlendMode((PDTransparencyGroup) xObject, groupsDone)) {
return true;
}
}
return false;
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class MergeAnnotationsTest method testAnnotationsMatch.
/*
* Source and target annotations are lĂnked by name with the target annotation's name
* being the source annotation's name prepended with 'annoRef_'
*/
private boolean testAnnotationsMatch(List<PDAnnotation> sourceAnnots, List<PDAnnotation> targetAnnots) {
Map<String, PDAnnotation> targetAnnotsByName = new HashMap<String, PDAnnotation>();
COSName destinationName;
// fill the map with the annotations destination name
for (PDAnnotation targetAnnot : targetAnnots) {
destinationName = (COSName) targetAnnot.getCOSObject().getDictionaryObject(COSName.DEST);
targetAnnotsByName.put(destinationName.getName(), targetAnnot);
}
// try to lookup the target annotation for the source annotation by destination name
for (PDAnnotation sourceAnnot : sourceAnnots) {
destinationName = (COSName) sourceAnnot.getCOSObject().getDictionaryObject(COSName.DEST);
if (targetAnnotsByName.get("annoRef_" + destinationName.getName()) == null) {
return false;
}
}
return true;
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class StandardSecurityHandler method prepareForDecryption.
/**
* Prepares everything to decrypt the document.
*
* Only if decryption of single objects is needed this should be called.
*
* @param encryption encryption dictionary
* @param documentIDArray document id
* @param decryptionMaterial Information used to decrypt the document.
*
* @throws InvalidPasswordException If the password is incorrect.
* @throws IOException If there is an error accessing data.
*/
@Override
public void prepareForDecryption(PDEncryption encryption, COSArray documentIDArray, DecryptionMaterial decryptionMaterial) throws IOException {
if (!(decryptionMaterial instanceof StandardDecryptionMaterial)) {
throw new IOException("Decryption material is not compatible with the document");
}
// This is only used with security version 4 and 5.
if (encryption.getVersion() >= 4) {
setStreamFilterName(encryption.getStreamFilterName());
setStringFilterName(encryption.getStreamFilterName());
}
setDecryptMetadata(encryption.isEncryptMetaData());
StandardDecryptionMaterial material = (StandardDecryptionMaterial) decryptionMaterial;
String password = material.getPassword();
if (password == null) {
password = "";
}
int dicPermissions = encryption.getPermissions();
int dicRevision = encryption.getRevision();
int dicLength = encryption.getVersion() == 1 ? 5 : encryption.getLength() / 8;
byte[] documentIDBytes = getDocumentIDBytes(documentIDArray);
// we need to know whether the meta data was encrypted for password calculation
boolean encryptMetadata = encryption.isEncryptMetaData();
byte[] userKey = encryption.getUserKey();
byte[] ownerKey = encryption.getOwnerKey();
byte[] ue = null, oe = null;
Charset passwordCharset = Charsets.ISO_8859_1;
if (dicRevision == 6 || dicRevision == 5) {
passwordCharset = Charsets.UTF_8;
ue = encryption.getUserEncryptionKey();
oe = encryption.getOwnerEncryptionKey();
}
if (dicRevision == 6) {
// PDFBOX-4155
password = SaslPrep.saslPrepQuery(password);
}
AccessPermission currentAccessPermission;
if (isOwnerPassword(password.getBytes(passwordCharset), userKey, ownerKey, dicPermissions, documentIDBytes, dicRevision, dicLength, encryptMetadata)) {
currentAccessPermission = AccessPermission.getOwnerAccessPermission();
setCurrentAccessPermission(currentAccessPermission);
byte[] computedPassword;
if (dicRevision == 6 || dicRevision == 5) {
computedPassword = password.getBytes(passwordCharset);
} else {
computedPassword = getUserPassword(password.getBytes(passwordCharset), ownerKey, dicRevision, dicLength);
}
encryptionKey = computeEncryptedKey(computedPassword, ownerKey, userKey, oe, ue, dicPermissions, documentIDBytes, dicRevision, dicLength, encryptMetadata, true);
} else if (isUserPassword(password.getBytes(passwordCharset), userKey, ownerKey, dicPermissions, documentIDBytes, dicRevision, dicLength, encryptMetadata)) {
currentAccessPermission = new AccessPermission(dicPermissions);
currentAccessPermission.setReadOnly();
setCurrentAccessPermission(currentAccessPermission);
encryptionKey = computeEncryptedKey(password.getBytes(passwordCharset), ownerKey, userKey, oe, ue, dicPermissions, documentIDBytes, dicRevision, dicLength, encryptMetadata, false);
} else {
throw new InvalidPasswordException("Cannot decrypt PDF, the password is incorrect");
}
if (dicRevision == 6 || dicRevision == 5) {
validatePerms(encryption, dicPermissions, encryptMetadata);
}
if (encryption.getVersion() == 4 || encryption.getVersion() == 5) {
// detect whether AES encryption is used. This assumes that the encryption algo is
// stored in the PDCryptFilterDictionary
// However, crypt filters are used only when V is 4 or 5.
PDCryptFilterDictionary stdCryptFilterDictionary = encryption.getStdCryptFilterDictionary();
if (stdCryptFilterDictionary != null) {
COSName cryptFilterMethod = stdCryptFilterDictionary.getCryptFilterMethod();
setAES(COSName.AESV2.equals(cryptFilterMethod) || COSName.AESV3.equals(cryptFilterMethod));
}
}
}
Aggregations