# PDFString Class

> Represents an array of unsigned bytes within a PDF document.

- Product: Adobe PDF Library 21
- Language: Modern C++
- Version: 21.4.0
- HTML page: https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFString
- Version index: https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/llms.txt

```cpp
class PDFString : PDFObject
```

**Namespace:** `datalogics_interface`

**Inherits from:** [`PDFObject`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFObject.md)

## Description

Represents an array of unsigned bytes within a PDF document.

A PDFString is a single data element that represents an array of unsigned bytes. It may be inserted into any collection object. PDFString may be a string of human readable text, but this is not required, and it may be stored either as characters or as hex values.

**Uses types:** [`PDFObjectType`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/PDFObjectType.md)

## Constructors

### PDFString

```cpp
datalogics_interface::PDFString::PDFString(const std::string &value, Document &doc, bool indirect, bool stored_as_hex=false)
```

*constructor*

**Parameters**

- `value` (`const std::string &`): Array of bytes stored in this PDFString
- `doc` ([`Document &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Document.md)): Document object containing this PDFString
- `indirect` (`bool`): flag marking this as an indirect PDFObject
- `stored_as_hex` (`bool`): flag indicating this PDFString should be stored as hex values

General constructor

## Methods

### get_bytes

```cpp
std::vector< unsigned char > datalogics_interface::PDFString::get_bytes() const
```

**Returns:** `std::vector< unsigned char >`

A byte array containing the raw data of this PDFString.

The raw byte array of this PDFString.

This method returns the raw data of the PDFString, without respect to any encoding. It should be used when the contents of the object represent data instead of human readable text, or when direct access to the underlying data is required.

### get_generation

```cpp
int datalogics_interface::PDFObject::get_generation() const
```

**Returns:** `int`

The generation number of this indirect object.

The generation number for this object.

Only indirect objects have a generation number.

### get_id

```cpp
int datalogics_interface::PDFObject::get_id() const
```

**Returns:** `int`

The ID number of this indirect object.

The ID number for this object.

Only indirect objects have an ID number.

### get_indirect

```cpp
bool datalogics_interface::PDFObject::get_indirect() const
```

**Returns:** `bool`

true if this object is indirect, false if it is direct.

Indicates if this object is indirect or direct.

### get_stored_as_hex

```cpp
bool datalogics_interface::PDFString::get_stored_as_hex() const
```

**Returns:** `bool`

true if this PDFString is stored as hex values, false otherwise.

Indicates that the data is stored as hexadecimal values.

### get_type

```cpp
PDFObjectType datalogics_interface::PDFObject::get_type() const
```

**Returns:** [`PDFObjectType`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/PDFObjectType.md)

The underlying Cos type of this object. Prefer this over dynamic_cast/try_as chains in hot paths.

### get_value

```cpp
std::string datalogics_interface::PDFString::get_value() const
```

**Returns:** `std::string`

The string value of this PDFString, converted to a Unicode string.

The byte array as a native string object.

This is a convenience for typical uses where a PDFString holds a human readable string instead of a byte array.

The text may be encoded within the PDF as either UTF-16BE or PDFDocEncoding; in either case, it will be converted to a Unicode string object appropriate to the platform.

If you need to access the contents of the PDFString object without respect to an encoding, use the Bytes property.

### operator!=

```cpp
bool datalogics_interface::PDFObject::operator!=(const PDFObject &other) const
```

**Parameters**

- `other` ([`const PDFObject &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFObject.md))

**Returns:** `bool`

true if `other` is not equal to this.

Inequality.

### operator==

```cpp
bool datalogics_interface::PDFObject::operator==(const PDFObject &other) const
```

**Parameters**

- `other` ([`const PDFObject &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFObject.md)): The other PDFObject to compare against.

**Returns:** `bool`

true if the two objects are equal, false otherwise.

Compare if two objects are equal.

### to_string

```cpp
std::string datalogics_interface::PDFObject::to_string() const
```

**Returns:** `std::string`

A string describing this PDFObject.

Returns a string representation of this PDFObject.

The string includes the object's indirect status, and if indirect, its ID and generation number.

### try_as

```cpp
T * datalogics_interface::PDFObject::try_as()
```

**Parameters**

- (unnamed) (`typename T`)

**Returns:** `T *`

Attempt to downcast this object to a derived Cos type such as `PDFString`, `PDFDict`, `PDFArray`, `PDFStream`, `PDFName`, `PDFInteger`, `PDFReal`, or `PDFBoolean`. Returns nullptr if the object's actual type doesn't match `T`.

### try_as

```cpp
const T * datalogics_interface::PDFObject::try_as() const
```

**Parameters**

- (unnamed) (`typename T`)

**Returns:** `const T *`

Const overload of try_as(). Returns a const pointer, or nullptr.
