private String toUnicodeString(PdfString pdfString) { return pdfString != null ? pdfString.toUnicodeString() : null; } }
@Override protected void checkPdfString(PdfString string) { if (string.getValueBytes().length > getMaxStringLength()) { throw new PdfAConformanceException(PdfAConformanceException.PDF_STRING_IS_TOO_LONG); } }
/** * Constructs a namespace defined by the given namespace name. * @param namespaceName a {@link String} defining the namespace name (conventionally a uniform * resource identifier, or URI). */ public PdfNamespace(String namespaceName) { this(new PdfString(namespaceName)); }
@Override protected void generateContent() { content = encodeBytes(getValueBytes()); }
@Override public String toString() { if (value == null) { return new String(decodeContent()); } else { return getValue(); } }
/** * Sets the /Contents value to the specified byte[]. * * @param contents a byte[] representing the digest */ public void setContents(byte[] contents) { PdfString contentsString = new PdfString(contents).setHexWriting(true); contentsString.markAsUnencryptedObject(); put(PdfName.Contents, contentsString); }
dic2.put(PdfName.Contents, new PdfString(paddedSig).setHexWriting(true)); close(dic2);
if (cert == null) cert = signature.getPdfObject().getAsArray(PdfName.Cert).getAsString(0); pk = new PdfPKCS7(PdfEncodings.convertToBytes(contents.getValue(), null), cert.getValueBytes(), provider); } else pk = new PdfPKCS7(PdfEncodings.convertToBytes(contents.getValue(), null), sub, provider); updateByteRange(pk, signature); PdfString date = signature.getDate(); if (date != null) pk.setSignDate(PdfDate.decode(date.toString())); String signName = signature.getName(); pk.setSignName(signName);
private void updateProducerInInfoDictionary() { String producer = null; if (reader == null) { producer = versionInfo.getVersion(); } else { if (info.getPdfObject().containsKey(PdfName.Producer)) { producer = info.getPdfObject().getAsString(PdfName.Producer).toUnicodeString(); } producer = addModifiedPostfix(producer); } info.getPdfObject().put(PdfName.Producer, new PdfString(producer)); }
/** * Encrypt content of {@code value} and set as content. {@code generateContent()} won't be called. * * @param encrypt @see PdfEncryption * @return true if value was encrypted, otherwise false. */ protected boolean encrypt(PdfEncryption encrypt) { if (checkState(PdfObject.UNENCRYPTED)) { return false; } if (encrypt != decryption) { if (decryption != null) { generateValue(); } if (encrypt != null && !encrypt.isEmbeddedFilesOnly()) { byte[] b = encrypt.encryptByteArray(getValueBytes()); content = encodeBytes(b); return true; } } return false; }
/** * Simple method that compares two given PdfStrings. * * @param outString string to compare. * @param cmpString string to compare. * @return true if strings are equal, otherwise false. */ public boolean compareStrings(PdfString outString, PdfString cmpString) { return cmpString.getValue().equals(outString.getValue()); }
/** * Split PDF string into array of single character PDF strings. * * @param string PDF string to be split. * @return split PDF string. */ private PdfString[] splitString(PdfString string) { checkGraphicsState(); PdfFont font = gs.getFont(); if (font instanceof PdfType0Font) { // Number of bytes forming one glyph can be arbitrary from [1; 4] range List<PdfString> strings = new ArrayList<>(); GlyphLine glyphLine = gs.getFont().decodeIntoGlyphLine(string); for (int i = glyphLine.start; i < glyphLine.end; i++) { strings.add(new PdfString(gs.getFont().convertToBytes(glyphLine.get(i)))); } return strings.toArray(new PdfString[strings.size()]); } else { // One byte corresponds to one character PdfString[] strings = new PdfString[string.getValue().length()]; for (int i = 0; i < string.getValue().length(); i++) { strings[i] = new PdfString(string.getValue().substring(i, i + 1), string.getEncoding()); } return strings; } }
case PdfObject.STRING: PdfString str = (PdfString) obj; if (str.isHexWriting()) { sb.append("<"); byte b[] = str.getValueBytes(); int len = b.length; String hex;
@Override public int hashCode() { String v = getValue(); String e = getEncoding(); int result = v != null ? v.hashCode() : 0; return 31 * result + (e != null ? e.hashCode() : 0); }
/** * Gets name of the file in the EmbeddedFiles name tree for the child target located * in the EmbeddedFiles. * * @return the name of the child file for this target */ public String getName() { return getPdfObject().getAsString(PdfName.N).toString(); }
/** * Returns the Unicode {@code String} value of this * {@code PdfString}-object. */ public String toUnicodeString() { if (encoding != null && encoding.length() != 0) { return getValue(); } if (content == null) { generateContent(); } byte[] b = decodeContent(); if (b.length >= 2 && b[0] == (byte) 0xFE && b[1] == (byte) 0xFF) { return PdfEncodings.convertToString(b, PdfEncodings.UNICODE_BIG); } else if (b.length >= 3 && b[0] == (byte)0xEF && b[1] == (byte)0xBB && b[2] == (byte)0xBF) { return PdfEncodings.convertToString(b, PdfEncodings.UTF8); } else { return PdfEncodings.convertToString(b, PdfEncodings.PDF_DOC_ENCODING); } }
private void write(PdfString pdfString) { pdfString.encrypt(crypto); if (pdfString.isHexWriting()) { writeByte('<'); writeBytes(pdfString.getInternalContent()); writeByte('>'); } else { writeByte('('); writeBytes(pdfString.getInternalContent()); writeByte(')'); } }
originalFileId = ByteUtils.getIsoBytes(writer.properties.initialDocumentId.getValue()); secondId = ByteUtils.getIsoBytes(writer.properties.modifiedDocumentId.getValue()); if (!originalModifiedDocumentId.equals(newModifiedId)) { secondId = ByteUtils.getIsoBytes(newModifiedId.getValue()); } else { secondId = PdfEncryption.generateNewDocumentId();
private static PdfArray getIndexedCsArray(PdfObject base, int hival, PdfString lookup) { PdfArray indexed = new PdfArray(); indexed.add(PdfName.Indexed); indexed.add(base); indexed.add(new PdfNumber(hival)); indexed.add(lookup.setHexWriting(true)); return indexed; }