Class 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 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)
      • 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:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object