Package com.pd4ml.pdf.cos
Class COSString
- java.lang.Object
-
- com.pd4ml.pdf.cos.COSBase
-
- com.pd4ml.pdf.cos.COSString
-
- All Implemented Interfaces:
COSObjectable
public final class COSString extends COSBase
A PDF string object. PDF strings are fundamentally byte strings (written in a source file either as a literal(...)or as hex<...>); this class stores the raw bytes and offers convenience decoding for the "text string" convention (a UTF-16BE BOM, or else PDFDocEncoding/Latin-1) used by metadata-ish fields such as titles and outline labels.
-
-
Constructor Summary
Constructors Constructor Description COSString(byte[] bytes)COSString(java.lang.String text)Builds a COSString from a Java string, encoding as PDFDocEncoding when every character fits in Latin-1, otherwise as UTF-16BE with a leading BOM (the standard PDF "text string" convention).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(ICOSVisitor<T> visitor)booleanequals(java.lang.Object other)byte[]getBytes()java.lang.StringgetString()Decodes the raw bytes as a PDF "text string": UTF-16BE if a BOM (FE FF) is present, PDFDocEncoding-as-Latin-1 otherwise.inthashCode()booleanisForceHexForm()static COSStringparseHex(java.lang.String hex)static COSStringparseLiteral(byte[] rawBytes)voidsetForceHexForm(boolean forceHexForm)java.lang.StringtoString()-
Methods inherited from class com.pd4ml.pdf.cos.COSBase
getCOSObject, getGenerationNumber, getKey, getObjectNumber, isDirect, resolve, setKey
-
-
-
-
Constructor Detail
-
COSString
public COSString(byte[] bytes)
-
COSString
public COSString(java.lang.String text)
Builds a COSString from a Java string, encoding as PDFDocEncoding when every character fits in Latin-1, otherwise as UTF-16BE with a leading BOM (the standard PDF "text string" convention).
-
-
Method Detail
-
parseLiteral
public static COSString parseLiteral(byte[] rawBytes)
-
parseHex
public static COSString parseHex(java.lang.String hex) throws COSException
- Throws:
COSException
-
getBytes
public byte[] getBytes()
-
setForceHexForm
public void setForceHexForm(boolean forceHexForm)
-
isForceHexForm
public boolean isForceHexForm()
-
getString
public java.lang.String getString()
Decodes the raw bytes as a PDF "text string": UTF-16BE if a BOM (FE FF) is present, PDFDocEncoding-as-Latin-1 otherwise. This is a simplification of full PDFDocEncoding (which differs from Latin-1 in a handful of code points above 0x7F) adequate for the vast majority of real-world documents.
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
accept
public <T> T accept(ICOSVisitor<T> visitor) throws COSException
- Specified by:
acceptin classCOSBase- Throws:
COSException
-
-