PdfString Class

A string: a sequence of bytes (ISO 32000-2, 7.3.4). It is immutable.

public sealed class PdfString : PdfObject, IEquatable<PdfString>

Remarks

A text string (7.9.2.2) is encoded with PDFDocEncoding, UTF-16BE or UTF-8, the last two with a byte order mark: PdfString.FromText and PdfString.ToText convert it.

Inheritance
PdfObject PdfString
Implements

Properties

NameDescription
BytesGets the bytes of the string.
IsHexadecimalGets a value indicating whether the string is written in hexadecimal form (<48656C6C6F>) rather than as a literal ((Hello)).
KindGets the kind of the object.

Gets the bytes of the string.

public ReadOnlyMemory<byte> Bytes { get; }

Property value

ReadOnlyMemory<byte>

IsHexadecimal

PdfString.cs

Gets a value indicating whether the string is written in hexadecimal form (<48656C6C6F>) rather than as a literal ((Hello)).

public bool IsHexadecimal { get; }

Property value

bool

Gets the kind of the object.

public override PdfObjectKind Kind { get; }

Property value

PdfObjectKind

Methods

NameDescription
Equals(PdfString?)Indicates whether the current object is equal to another object of the same type.
Equals(object?)Determines whether the specified object is equal to the current object.
FromBytes(ReadOnlySpan<byte>, bool)Creates a string from bytes.
FromText(string)Creates a text string (ISO 32000-2, 7.9.2.2): PDFDocEncoding when every character has a code in it, otherwise UTF-16BE with a byte order mark.
GetHashCode()Serves as the default hash function.
ToText()Decodes the string as a text string (ISO 32000-2, 7.9.2.2): UTF-16BE or UTF-8 when it starts with their byte order mark, otherwise PDFDocEncoding.

Equals overloads

Equals(PdfString?)

PdfString.cs

Indicates whether the current object is equal to another object of the same type.

public bool Equals(PdfString? other)
Parameters
other PdfString?
An object to compare with this object.
Returns

bool true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

PdfString.cs

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)
Parameters
obj object?
The object to compare with the current object.
Returns

bool true if the specified object is equal to the current object; otherwise, false.

FromBytes(ReadOnlySpan<byte>, bool)

PdfString.cs

Creates a string from bytes.

public static PdfString FromBytes(ReadOnlySpan<byte> bytes, bool hexadecimal = false)

Parameters

bytes ReadOnlySpan<byte>
The bytes.
hexadecimal bool
Whether the string is written in hexadecimal form.

Returns

PdfString The string.

FromText(string)

PdfString.cs

Creates a text string (ISO 32000-2, 7.9.2.2): PDFDocEncoding when every character has a code in it, otherwise UTF-16BE with a byte order mark.

public static PdfString FromText(string text)

Parameters

text string
The text.

Returns

PdfString The string.

GetHashCode()

PdfString.cs

Serves as the default hash function.

public override int GetHashCode()

Returns

int A hash code for the current object.

ToText()

PdfString.cs

Decodes the string as a text string (ISO 32000-2, 7.9.2.2): UTF-16BE or UTF-8 when it starts with their byte order mark, otherwise PDFDocEncoding.

public string ToText()

Returns

string The text. A byte that has no character in PDFDocEncoding gives U+FFFD.