Table of Contents

Class PdfString

Namespace
MiPdf.Objects
Assembly
MiPdf.dll

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

bytes byte[]

The raw bytes; the array is used directly, not copied.

hex bool

True to prefer serialization as hexadecimal string (IsHex).

Exceptions

ArgumentNullException

bytes is null.

PdfString(string)

Creates a text string (PDFDocEncoding if possible, otherwise UTF-16BE with BOM).

public PdfString(string text)

Parameters

text string

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

bool

ObjectType

The kind of this object.

public override PdfObjectType ObjectType { get; }

Property Value

PdfObjectType

Text

Decodes the string as a PDF text string.

public string Text { get; }

Property Value

string

Methods

Clone()

Creates a copy with a copy of the byte array.

public override PdfObject Clone()

Returns

PdfObject

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

bytes ReadOnlySpan<byte>

Returns

string

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

text string

Returns

byte[]

Equals(object?)

True if obj is a PdfString with the same bytes (IsHex is ignored).

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.