Refine search
/** * This is a convenience method that will get the dictionary object that is expected to be a name and convert it to * a string. Null is returned if the entry does not exist in the dictionary. * * @param key The key to the item in the dictionary. * @return The name converted to a string. */ public String getNameAsString(COSName key) { String retval = null; COSBase name = getDictionaryObject(key); if (name instanceof COSName) { retval = ((COSName) name).getName(); } else if (name instanceof COSString) { retval = ((COSString) name).getString(); } return retval; }
public final byte[] getPanoseBytes(COSDictionary style) { if (style != null) { COSString panose = (COSString)style.getDictionaryObject(COSName.PANOSE); return panose.getBytes(); } return null; } }
/** * (Optional) A list of array of bytes containing DER-encoded X.509v3 certificates of acceptable * issuers. If the signer’s certificate chains up to any of the specified issuers (either * directly or indirectly), the certificate is considered acceptable for signing. * * @param issuers A list of byte array containing DER-encoded X.509v3 certificates */ public void setIssuer(List<byte[]> issuers) { COSArray array = new COSArray(); for (byte[] issuer : issuers) { array.add(new COSString(issuer)); } this.dictionary.setItem(COSName.ISSUER, array); }
/** * Sets the contents. * * @param bytes contents to be used */ public void setContents(byte[] bytes) { COSString string = new COSString(bytes); string.setForceHexForm(true); dictionary.setItem(COSName.CONTENTS, string); }
private String getTextString(COSString cosString) { String text = cosString.getString(); for (char c : text.toCharArray()) { if (Character.isISOControl(c)) { text = "<" + cosString.toHexString() + ">"; break; } } return "" + text; }
/** * This will output the given byte getString as a PDF object. * * @param string COSString to be written * @param output The stream to write to. * @throws IOException If there is an error writing to the stream. */ public static void writeString(COSString string, OutputStream output) throws IOException { writeString(string.getBytes(), string.getForceHexForm(), output); }
PDDocument doc = new PDDocument(); PDPage page = new PDPage(); doc.addPage(page); COSDictionary acroFormDict = new COSDictionary(); acroFormDict.setBoolean(COSName.getPDFName("NeedAppearances"), true); acroFormDict.setItem(COSName.getPDFName("Fields"), new COSArray()); doc.getDocumentCatalog().setAcroForm(acroForm); COSDictionary cosDict = new COSDictionary(); COSArray rect = new COSArray(); rect.add(new COSFloat(100)); rect.add(new COSFloat(10)); rect.add(new COSFloat(200)); cosDict.setItem(COSName.TYPE, COSName.ANNOT); cosDict.setItem(COSName.SUBTYPE, COSName.getPDFName("Widget")); cosDict.setItem(COSName.T, new COSString("Btn"+1)); cosDict.setItem(COSName.V, new COSString("Validate")); cosDict.setItem(COSName.DA, new COSString("/Helv 7 Tf 0 g")); cosDict.setInt(COSName.FF, 65536);
PDDocument pdfDoc = PDDocument.load(SOURCE); PDDocumentCatalog docCatalog = pdfDoc.getDocumentCatalog(); PDAcroForm acroForm = docCatalog.getAcroForm(); for (Object field : acroForm.getFields()) { if (field instanceof PDVariableText) { COSDictionary dict = ((PDField)field).getDictionary(); COSString defaultAppearance = (COSString) dict.getDictionaryObject(COSName.DA); if (defaultAppearance != null) dict.setString(COSName.DA, defaultAppearance.getString() + " 1 0 0 rg "); field = field instanceof PDTextbox ? new PDTextbox(acroForm, dict) : new PDChoiceField(acroForm, dict); ((PDField)field).setValue(VALUE); } } pdfDoc.save(TARGET); pdfDoc.close();
throws IOException COSArray idArray = document.getDocument().getDocumentID(); if (idArray == null || idArray.size() < 2) 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)); COSString idString = new COSString(id); idArray = new COSArray(); idArray.add(idString); idArray.add(idString); document.getDocument().setDocumentID(idArray); ownerBytes, permissionInt, id.getBytes(), revision, length, true); null, null, null, permissionInt, id.getBytes(), revision, length, true, false);
PDDocument doc = new PDDocument(); PDPage page = new PDPage(); doc.addPage(page); PDAcroForm acroForm = new PDAcroForm(doc); doc.getDocumentCatalog().setAcroForm(acroForm); COSDictionary cosDict = new COSDictionary(); COSArray rect = new COSArray(); rect.add(new COSFloat(250f)); // lower x boundary rect.add(new COSFloat(75f)); // lower y boundary rect.add(new COSFloat(500f)); // upper x boundary rect.add(new COSFloat(125f)); // upper y boundary cosDict.setItem(COSName.RECT, rect); cosDict.setItem(COSName.FT, COSName.getPDFName("Tx")); // Field Type cosDict.setItem(COSName.TYPE, COSName.ANNOT); cosDict.setItem(COSName.SUBTYPE, COSName.getPDFName("Widget")); cosDict.setItem(COSName.T, new COSString("yourFieldName")); PDTextbox textField = new PDTextbox(acroForm, cosDict); acroForm.getFields().add(textField); page.getAnnotations().add(textField.getWidget());
Long idTime = doc.getDocumentId() == null ? System.currentTimeMillis() : doc.getDocumentId(); if(doc.isAllSecurityToBeRemoved()) COSDocument cosDoc = doc.getDocument(); COSDictionary trailer = cosDoc.getTrailer(); trailer.removeItem(COSName.ENCRYPT); COSArray idArray; boolean missingID = true; COSBase base = trailer.getDictionaryObject(COSName.ID); if (base instanceof COSArray) if (idArray.size() == 2) idArray = new COSArray(); COSDictionary info = (COSDictionary)trailer.getDictionaryObject( COSName.INFO ); if( info != null ) COSString firstID = missingID ? new COSString( md5.digest() ) : (COSString)idArray.get(0); COSString secondID = missingID ? firstID : new COSString( md5.digest() ); idArray = new COSArray(); idArray.add( firstID );
for (COSName key : dict.keySet()) crawl(dict.getDictionaryObject(key)); for (COSObject obj : doc.getDocument().getObjects()) for (COSString s : strings) String str = s.getString(); if (!str.contains("\n")) doc.close();
try (PDDocument document = PDDocument.load(infile, password)) for (PDSignature sig : document.getSignatureDictionaries()) COSString contents = (COSString) sigDict.getDictionaryObject(COSName.CONTENTS); long rangeMax = byteRange[2] + (long) byteRange[3]; int contentLen = contents.getString().length() * 2 + 2; if (fileLen != rangeMax || byteRange[0] != 0 || byteRange[1] + contentLen != byteRange[2]) byte[] certData = contents.getBytes(); CertificateFactory factory = CertificateFactory.getInstance("X.509"); ByteArrayInputStream certStream = new ByteArrayInputStream(certData); COSString certString = (COSString) sigDict.getDictionaryObject(COSName.CERT); return; byte[] certData = certString.getBytes(); CertificateFactory factory = CertificateFactory.getInstance("X.509"); ByteArrayInputStream certStream = new ByteArrayInputStream(certData);
key = entry.getKey().getName(); object = toTreeObject(entry.getValue()); value = entry.getValue(); String text = ((COSString) nodeValue).getString(); text = "<" + ((COSString) nodeValue).toHexString() + ">"; break; result = ((COSName) nodeValue).getName(); if (COSName.XREF.equals(dict.getCOSName(COSName.TYPE))) result = "(" + dict.size() + ")"; result = "(" + array.size() + ")";
/** * 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; }
for( COSName key : map.keySet() ) COSBase cosObj = map.getDictionaryObject( key ); Object actualObject = null; if( cosObj instanceof COSString ) actualObject = ((COSString)cosObj).getString(); actualObject = ((COSName)cosObj).getName(); actualMap.put( key.getName(), actualObject );
private static String getHalftoneName(COSDictionary dict) { COSBase name = dict.getDictionaryObject(COSName.getPDFName("HalftoneName")); if (name instanceof COSName) { return ((COSName) name).getName(); } else if (name instanceof COSString) { return ((COSString) name).getString(); } else if (name != null) { return name.toString(); } else { return null; } }
COSArray array = (COSArray) encryption.getCOSDictionary().getItem(COSName.RECIPIENTS); if (array == null) array = (COSArray) defaultCryptFilterDictionary.getCOSDictionary().getItem(COSName.RECIPIENTS); byte[][] recipientFieldsBytes = new byte[array.size()][]; for (int i = 0; i < array.size(); i++) COSString recipientFieldString = (COSString) array.getObject(i); byte[] recipientBytes = recipientFieldString.getBytes(); CMSEnvelopedData data = new CMSEnvelopedData(recipientBytes); Collection<RecipientInformation> recipCertificatesIt = data.getRecipientInfos() setAES(COSName.AESV2.equals(cryptFilterMethod) || COSName.AESV3.equals(cryptFilterMethod));
/** * This will get the name of the destination. * * @return The name of the destination. */ public String getNamedDestination() { String retval = null; if( namedDestination instanceof COSString ) { retval = ((COSString)namedDestination).getString(); } else if( namedDestination instanceof COSName ) { retval = ((COSName)namedDestination).getName(); } return retval; }
COSBase idFirst = first.getItem(COSName.getPDFName(TRAILER_DICTIONARY_KEY_ID)); COSBase idLast = last.getItem(COSName.getPDFName(TRAILER_DICTIONARY_KEY_ID)); for (Object of : af.toList()) for (Object ol : al.toList()) oneIsEquals = ((COSString) ol).getString().equals(((COSString) of).getString());