Search in sources :

Example 16 with COSString

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);
}
Also used : COSString(com.tom_roush.pdfbox.cos.COSString)

Example 17 with COSString

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;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 18 with COSString

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;
}
Also used : COSString(com.tom_roush.pdfbox.cos.COSString) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 19 with COSString

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);
    }
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) BigInteger(java.math.BigInteger) MessageDigest(java.security.MessageDigest) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 20 with COSString

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;
}
Also used : COSString(com.tom_roush.pdfbox.cos.COSString)

Aggregations

COSString (com.tom_roush.pdfbox.cos.COSString)65 COSArray (com.tom_roush.pdfbox.cos.COSArray)33 COSBase (com.tom_roush.pdfbox.cos.COSBase)24 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)5 COSName (com.tom_roush.pdfbox.cos.COSName)5 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)4 Map (java.util.Map)4 COSBoolean (com.tom_roush.pdfbox.cos.COSBoolean)2 COSFloat (com.tom_roush.pdfbox.cos.COSFloat)2 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)2 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)2 MessageDigest (java.security.MessageDigest)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)1