use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.
the class PDFontDescriptor method setCharacterSet.
/**
* This will set the character set for the font.
*
* @param charSet The new character set for the font.
*/
public void setCharacterSet(String charSet) {
COSString name = null;
if (charSet != null) {
name = new COSString(charSet);
}
dic.setItem(COSName.CHAR_SET, name);
}
use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.
the class PDFontDescriptor method getPanose.
/**
* Returns the Panose entry of the Style dictionary, if any.
*
* @return A Panose wrapper object.
*/
public PDPanose getPanose() {
COSDictionary style = (COSDictionary) dic.getDictionaryObject(COSName.STYLE);
if (style != null) {
COSString panose = (COSString) style.getDictionaryObject(COSName.PANOSE);
byte[] bytes = panose.getBytes();
return new PDPanose(bytes);
}
return null;
}
use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.
the class PDFontDescriptor method getFontFamily.
/**
* A string representing the preferred font family.
*
* @return The font family.
*/
public String getFontFamily() {
String retval = null;
COSString name = (COSString) dic.getDictionaryObject(COSName.FONT_FAMILY);
if (name != null) {
retval = name.getString();
}
return retval;
}
use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.
the class StandardSecurityHandler method prepareEncryptionDictRev2345.
private void prepareEncryptionDictRev2345(String ownerPassword, String userPassword, PDEncryption encryptionDictionary, int permissionInt, PDDocument document, int revision, int length) throws IOException {
COSArray idArray = document.getDocument().getDocumentID();
// check if the document has an id yet. If it does not then generate one
if (idArray == null || idArray.size() < 2) {
MessageDigest md = MessageDigests.getMD5();
BigInteger time = BigInteger.valueOf(System.currentTimeMillis());
md.update(time.toByteArray());
md.update(ownerPassword.getBytes(Charsets.ISO_8859_1));
md.update(userPassword.getBytes(Charsets.ISO_8859_1));
md.update(document.getDocument().toString().getBytes(Charsets.ISO_8859_1));
byte[] id = md.digest(this.toString().getBytes(Charsets.ISO_8859_1));
COSString idString = new COSString(id);
idArray = new COSArray();
idArray.add(idString);
idArray.add(idString);
document.getDocument().setDocumentID(idArray);
}
COSString id = (COSString) idArray.getObject(0);
byte[] ownerBytes = computeOwnerPassword(ownerPassword.getBytes(Charsets.ISO_8859_1), userPassword.getBytes(Charsets.ISO_8859_1), revision, length);
byte[] userBytes = computeUserPassword(userPassword.getBytes(Charsets.ISO_8859_1), ownerBytes, permissionInt, id.getBytes(), revision, length, true);
encryptionKey = computeEncryptedKey(userPassword.getBytes(Charsets.ISO_8859_1), ownerBytes, null, null, null, permissionInt, id.getBytes(), revision, length, true, false);
encryptionDictionary.setOwnerKey(ownerBytes);
encryptionDictionary.setUserKey(userBytes);
if (revision == 4) {
prepareEncryptionDictAES(encryptionDictionary, COSName.AESV2);
}
}
use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.
the class StandardSecurityHandler method getDocumentIDBytes.
private byte[] getDocumentIDBytes(COSArray documentIDArray) {
// some documents may not have document id, see
// test\encryption\encrypted_doc_no_id.pdf
byte[] documentIDBytes;
if (documentIDArray != null && documentIDArray.size() >= 1) {
COSString id = (COSString) documentIDArray.getObject(0);
documentIDBytes = id.getBytes();
} else {
documentIDBytes = new byte[0];
}
return documentIDBytes;
}
Aggregations