Class PdfString
- java.lang.Object
-
- com.itextpdf.kernel.pdf.PdfObject
-
- com.itextpdf.kernel.pdf.PdfPrimitiveObject
-
- com.itextpdf.kernel.pdf.PdfString
-
public class PdfString extends PdfPrimitiveObject
APdfString
-class is the PDF-equivalent of a JAVA-String
-object.A string is a sequence of characters delimited by parenthesis. If a string is too long to be conveniently placed on a single line, it may be split across multiple lines by using the backslash character (\) at the end of a line to indicate that the string continues on the following line. Within a string, the backslash character is used as an escape to specify unbalanced parenthesis, non-printing ASCII characters, and the backslash character itself. Use of the \ddd escape sequence is the preferred way to represent characters outside the printable ASCII character set.
This object is described in the 'Portable Document Format Reference Manual version 1.7' section 3.2.3 (page 53-56).- See Also:
PdfObject
-
-
Field Summary
Fields Modifier and Type Field Description private int
decryptInfoGen
private int
decryptInfoNum
private PdfEncryption
decryption
protected java.lang.String
encoding
protected boolean
hexWriting
protected java.lang.String
value
-
Fields inherited from class com.itextpdf.kernel.pdf.PdfPrimitiveObject
content, directOnly
-
Fields inherited from class com.itextpdf.kernel.pdf.PdfObject
ARRAY, BOOLEAN, DICTIONARY, FLUSHED, FORBID_RELEASE, FREE, INDIRECT_REFERENCE, indirectReference, LITERAL, MODIFIED, MUST_BE_FLUSHED, MUST_BE_INDIRECT, NAME, NULL, NUMBER, ORIGINAL_OBJECT_STREAM, READ_ONLY, READING, STREAM, STRING, UNENCRYPTED
-
-
Constructor Summary
Constructors Modifier Constructor Description private
PdfString()
PdfString(byte[] content)
protected
PdfString(byte[] content, boolean hexWriting)
Only PdfReader can use this method!PdfString(java.lang.String value)
PdfString(java.lang.String value, java.lang.String encoding)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
copyContent(PdfObject from, PdfDocument document, ICopyFilter copyFilter)
Copies object content from object 'from'.protected byte[]
decodeContent()
protected byte[]
encodeBytes(byte[] bytes)
Escape special symbols or convert to hexadecimal string.protected boolean
encrypt(PdfEncryption encrypt)
Encrypt content ofvalue
and set as content.boolean
equals(java.lang.Object o)
protected void
generateContent()
protected void
generateValue()
java.lang.String
getEncoding()
Gets the encoding of this string.byte
getType()
Gets object type.java.lang.String
getValue()
byte[]
getValueBytes()
Gets bytes of String-value considering encoding.int
hashCode()
boolean
isHexWriting()
void
markAsUnencryptedObject()
Marks this string object as not encrypted in the encrypted document.protected PdfObject
newInstance()
Creates new instance of object.(package private) void
setDecryption(int decryptInfoNum, int decryptInfoGen, PdfEncryption decryption)
PdfString
setHexWriting(boolean hexWriting)
java.lang.String
toString()
java.lang.String
toUnicodeString()
Returns the UnicodeString
value of thisPdfString
-object.-
Methods inherited from class com.itextpdf.kernel.pdf.PdfPrimitiveObject
compareContent, getInternalContent, hasContent, makeIndirect, setIndirectReference
-
Methods inherited from class com.itextpdf.kernel.pdf.PdfObject
checkState, clearState, clone, clone, copyContent, copyTo, copyTo, copyTo, copyTo, equalContent, flush, flush, getIndirectReference, isArray, isBoolean, isDictionary, isFlushed, isIndirect, isIndirectReference, isLiteral, isModified, isName, isNull, isNumber, isReleaseForbidden, isStream, isString, makeIndirect, processCopying, processCopying, release, setModified, setState
-
-
-
-
Field Detail
-
value
protected java.lang.String value
-
encoding
protected java.lang.String encoding
-
hexWriting
protected boolean hexWriting
-
decryptInfoNum
private int decryptInfoNum
-
decryptInfoGen
private int decryptInfoGen
-
decryption
private PdfEncryption decryption
-
-
Constructor Detail
-
PdfString
public PdfString(java.lang.String value, java.lang.String encoding)
-
PdfString
public PdfString(java.lang.String value)
-
PdfString
public PdfString(byte[] content)
-
PdfString
protected PdfString(byte[] content, boolean hexWriting)
Only PdfReader can use this method!- Parameters:
content
- byte content thePdfString
will be created fromhexWriting
- boolean indicating if hex writing will be used
-
PdfString
private PdfString()
-
-
Method Detail
-
getType
public byte getType()
Description copied from class:PdfObject
Gets object type.
-
isHexWriting
public boolean isHexWriting()
-
setHexWriting
public PdfString setHexWriting(boolean hexWriting)
-
getValue
public java.lang.String getValue()
-
getEncoding
public java.lang.String getEncoding()
Gets the encoding of this string.- Returns:
- the name of the encoding specifying the byte representation of current
PdfString
value
-
toUnicodeString
public java.lang.String toUnicodeString()
Returns the UnicodeString
value of thisPdfString
-object.- Returns:
- Unicode string value created by current
PdfString
object
-
getValueBytes
public byte[] getValueBytes()
Gets bytes of String-value considering encoding.- Returns:
- byte array
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
markAsUnencryptedObject
public void markAsUnencryptedObject()
Marks this string object as not encrypted in the encrypted document.If it's marked so, it will be considered as already in plaintext and decryption will not be performed for it. In order to have effect, this method shall be called before
getValue()
andgetValueBytes()
methods.NOTE: this method is only needed in a very specific cases of encrypted documents. E.g. digital signature dictionary /Contents entry shall not be encrypted. Also this method isn't meaningful in non-encrypted documents.
-
setDecryption
void setDecryption(int decryptInfoNum, int decryptInfoGen, PdfEncryption decryption)
-
generateValue
protected void generateValue()
-
generateContent
protected void generateContent()
- Specified by:
generateContent
in classPdfPrimitiveObject
-
encrypt
protected boolean encrypt(PdfEncryption encrypt)
Encrypt content ofvalue
and set as content.generateContent()
won't be called.- Parameters:
encrypt
-PdfEncryption
instance- Returns:
- true if value was encrypted, otherwise false.
-
decodeContent
protected byte[] decodeContent()
-
encodeBytes
protected byte[] encodeBytes(byte[] bytes)
Escape special symbols or convert to hexadecimal string. This method don't change eithervalue
orcontent
ot thePdfString
.- Parameters:
bytes
- byte array to manipulate with.- Returns:
- Hexadecimal string or string with escaped symbols in byte array view.
-
newInstance
protected PdfObject newInstance()
Description copied from class:PdfObject
Creates new instance of object.- Specified by:
newInstance
in classPdfObject
- Returns:
- new instance of object.
-
copyContent
protected void copyContent(PdfObject from, PdfDocument document, ICopyFilter copyFilter)
Description copied from class:PdfObject
Copies object content from object 'from'.- Overrides:
copyContent
in classPdfPrimitiveObject
- Parameters:
from
- object to copy content from.document
- document to copy object to.copyFilter
-ICopyFilter
a filter that will apply on dictionaries and array UseNullCopyFilter
for no filtering
-
-