Class PdfString
A PDF string. Internally a byte sequence; Text interprets it as a text string (PDFDocEncoding, UTF-16BE or UTF-8 with byte order mark).
public sealed class PdfString : PdfObject
- Inheritance
-
PdfString
- Inherited Members
Constructors
PdfString(byte[], bool)
Creates a string from raw bytes.
public PdfString(byte[] bytes, bool hex = false)
Parameters
bytesbyte[]The raw bytes; the array is used directly, not copied.
hexboolTrue to prefer serialization as hexadecimal string (IsHex).
Exceptions
- ArgumentNullException
bytesis null.
PdfString(string)
Creates a text string (PDFDocEncoding if possible, otherwise UTF-16BE with BOM).
public PdfString(string text)
Parameters
textstring
Properties
Bytes
The raw bytes of the string (already decrypted when read from an encrypted file).
public byte[] Bytes { get; set; }
Property Value
- byte[]
IsHex
Preferred serialization as hexadecimal string.
public bool IsHex { get; set; }
Property Value
ObjectType
The kind of this object.
public override PdfObjectType ObjectType { get; }
Property Value
Text
Decodes the string as a PDF text string.
public string Text { get; }
Property Value
Methods
Clone()
Creates a copy with a copy of the byte array.
public override PdfObject Clone()
Returns
DecodeText(ReadOnlySpan<byte>)
Decodes a PDF text string: UTF-16BE or UTF-8 when the corresponding byte order mark is present (UTF-16LE with BOM is tolerated as well), otherwise PDFDocEncoding.
public static string DecodeText(ReadOnlySpan<byte> bytes)
Parameters
bytesReadOnlySpan<byte>
Returns
EncodeText(string)
Encodes text as a PDF text string: PDFDocEncoding if all characters can be encoded, otherwise UTF-16BE with byte order mark.
public static byte[] EncodeText(string text)
Parameters
textstring
Returns
- byte[]
Equals(object?)
public override bool Equals(object? obj)
Parameters
objobject
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.