Class: Obj

PDFNet. Obj


new Obj()

Obj is a concrete class for all SDF/Cos objects. Obj hierarchy implements the composite design pattern. As a result, you can invoke a member function of any 'derived' object through Obj interface. If the member function is not supported (e.g. if you invoke Obj::GetNumber() on a boolean object) an Exception will be thrown.

You can use GetType() or obl.Is???() member functions to find out type-information at run time, however most of the time the type can be inferred from the PDF specification. Therefore when you call Doc::GetTrailer() you can assume that returned object is a dictionary. If there is any ambiguity use Is???() methods.

Objects can't be shared across documents, however you can use Doc::ImportObj() to copy objects from one document to another.

Objects can be shared within a document provided that they are created as indirect. Indirect objects are the ones that are referenced in cross-reference table. To create an object as indirect use doc.CreateIndirect???() (where ? is the Object type).

Methods


erase(pos)

Removes an element in the dictionary from specified position.

Parameters:
Name Type Description
pos PDFNet.DictIterator

A dictionary iterator indicating the position of the element to remove.


eraseAt(pos)

Checks whether the position is within the array bounds and then removes it from the array and moves each subsequent element to the slot with the next smaller index and decrements the arrays length by 1.

Parameters:
Name Type Description
pos number

The index for the array member to remove. Array indexes start at 0.


eraseFromKey(key)

Removes an element in the dictionary that matches the given key.

Parameters:
Name Type Description
key string

A string representing the key value of the element to remove.


find(key)

Search the dictionary for a given key.

Parameters:
Name Type Description
key string

a key to search for in the dictionary

Returns:

A promise that resolves to the iterator to the matching key/value pair or invalid iterator (i.e. itr.HasNext()==fase) if the if the dictionary does not contain the given key.

Type
PDFNet.DictIterator

findObj(key)

Search the dictionary for a given key.

Parameters:
Name Type Description
key string

a key to search for in the dictionary

Returns:

A promise that resolves to nULL if the dictionary does not contain the specified key. Otherwise return the corresponding value.

Type
PDFNet.Obj

get(key)

Search the dictionary for a given key and throw an exception if the key is not found.

Parameters:
Name Type Description
key string

a key to search for in the dictionary

Returns:

A promise that resolves to obj::Null object if the value matching specified key is a Obj::Null object. otherwise return the iterator to the matching key/value pair.

Type
PDFNet.DictIterator

getAsPDFText()

Convert the SDF/Cos String object to 'PDF Text String' (a Unicode string).

PDF Text Strings are not used to represent page content, however they are used in text annotations, bookmark names, article names, document information etc. These strings are encoded in either PDFDocEncoding or Unicode character encoding. For more information on PDF Text Strings, please refer to section 3.8.1 'Text Strings' in PDF Reference.

Returns:

A promise that resolves to the Unicode string of the SDF/Cos String object

Type
string

getAt(index)

Parameters:
Name Type Description
index number

The array element to obtain. The first element in an array has an index of zero.

Returns:

A promise that resolves to an object of type: "Obj"

Type
PDFNet.Obj

getBool()

Returns:

A promise that resolves to bool value if this is Bool.

Type
boolean

getBuffer()

Returns:

A promise that resolves to a pointer to the string buffer. Please note that the string may not be NULL terminated and that it may not be represented in ASCII or Unicode encoding. For more information on SDF/Cos String objects, please refer to section 3.2.3 'String Objects' in PDF Reference Manual.

Type
number

getDecodedStream()

Returns:

A promise that resolves to A filter to the decoded stream

Type
PDFNet.Filter

getDictIterator()

Returns:

A promise that resolves to an iterator that addresses the first element in the dictionary.

 DictIterator itr = dict.GetDictIterator();
 while (itr.HasNext()) {
     Obj key = itr.Key();
     Obj value = itr.Value();
     // ...
     itr.Next()
  }
Type
PDFNet.DictIterator

getDoc()

Returns:

A promise that resolves to the document to which this object belongs.

Type
PDFNet.SDFDoc

getGenNum()

Returns:

A promise that resolves to generation number. If this is not an Indirect object, generation number of a containing indirect object is returned.

Type
number

getName()

Returns:

A promise that resolves to string representing the Name object.

Type
string

getNumber()

Returns:

A promise that resolves to value, if this is Number.

Type
number

getObjNum()

Returns:

A promise that resolves to object number. If this is not an Indirect object, object number of a containing indirect object is returned.

Type
number

getOffset()

Returns:

A promise that resolves to object offset from the beginning of the file. If this is not an Indirect object, offset of a containing indirect object is returned.

Type
number

getRawStream(decrypt)

Parameters:
Name Type Description
decrypt boolean

If true decrypt the stream if the stream is encrypted.

Returns:

A promise that resolves to A filter to the encoded stream

Type
PDFNet.Filter

getRawStreamLength()

Returns:

A promise that resolves to the length of the raw/encoded stream equal to the Length parameter

Type
number

getType()

Returns:

A promise that resolves to the object type.

Type
number
Example
Return value enum:
<pre>
PDFNet.Obj.Type = {
	e_null : 0
	e_bool : 1
	e_number : 2
	e_name : 3
	e_string : 4
	e_dict : 5
	e_array : 6
	e_stream : 7
}
</pre>

insert(pos, input_obj)

Inserts an existing Obj in this array.

Parameters:
Name Type Description
pos number

The location in the array to insert the object . The object is inserted before the specified location. The first element in an array has a pos of zero. If pos >= Array->Length(), appends obj to array.

input_obj PDFNet.Obj

The value to be inserted into the dictionary. If 'obj' is indirect (i.e. is a shared) object it will be inserted by reference, otherwise the object will be cloned and then inserted.

Returns:

A promise that resolves to a newly inserted object.

Type
PDFNet.Obj

insertArray(pos)

Inserts an Obj::Type::e_array object in the array.

Parameters:
Name Type Description
pos number

The location in the array to insert the object . The object is inserted before the specified location. The first element in an array has a pos of zero. If pos >= Array->Length(), appends obj to array.

Returns:

A promise that resolves to a newly created array object.

Type
PDFNet.Obj

insertBool(pos, value)

Inserts an Obj::Type::e_bool object in the array.

Parameters:
Name Type Description
pos number

The location in the array to insert the object . The object is inserted before the specified location. The first element in an array has a pos of zero. If pos >= Array->Length(), appends obj to array.

value boolean

The value of the Obj::Type::e_bool object to be inserted.

Returns:

A promise that resolves to a newly created boolean object.

Type
PDFNet.Obj

insertDict(pos)

Inserts an Obj::Type::e_dict object in the array.

Parameters:
Name Type Description
pos number

The location in the array to insert the object . The object is inserted before the specified location. The first element in an array has a pos of zero. If pos >= Array->Length(), appends obj to array.

Returns:

A promise that resolves to a newly created dictionary object.

Type
PDFNet.Obj

insertMatrix(pos, mtx)

Inserts an array of 6 numbers in this array.

Parameters:
Name Type Description
pos number

The location in the array to insert the object . The object is inserted before the specified location. The first element in an array has a pos of zero. If pos >= Array->Length(), appends obj to array.

mtx PDFNet.matrix2d

A matrix used to set the values in an array of six numbers. The resulting array will be then inserted in this array.

Returns:

A promise that resolves to a newly created array object.

Type
PDFNet.Obj

insertName(pos, name)

Inserts an Obj::Type::e_name object in the array.

Parameters:
Name Type Description
pos number

The location in the array to insert the object . The object is inserted before the specified location. The first element in an array has a pos of zero. If pos >= Array->Length(), appends obj to array.

name string

The value of the Obj::Type::e_name object to be inserted.

Returns:

A promise that resolves to a newly created name object.

Type
PDFNet.Obj

insertNull(pos)

Inserts an Obj::Type::e_null object in the array.

Parameters:
Name Type Description
pos number

The location in the array to insert the object . The object is inserted before the specified location. The first element in an array has a pos of zero. If pos >= Array->Length(), appends obj to array.

Returns:

A promise that resolves to a newly created null object.

Type
PDFNet.Obj

insertNumber(pos, value)

Inserts an Obj::Type::e_number object in the array.

Parameters:
Name Type Description
pos number

The location in the array to insert the object . The object is inserted before the specified location. The first element in an array has a pos of zero. If pos >= Array->Length(), appends obj to array.

value number

The value of the Obj::Type::e_number object to be inserted.

Returns:

A promise that resolves to a newly created number object.

Type
PDFNet.Obj

insertRect(pos, x1, y1, x2, y2)

Inserts an array of 4 numbers in this array.

Parameters:
Name Type Description
pos number

The location in the array to insert the object . The object is inserted before the specified location. The first element in an array has a pos of zero. If pos >= Array->Length(), appends obj to array.

x1 number

The bottom left x value of the rect to be inserted

y1 number

The bottom left y value of the rect to be inserted

x2 number

The top right x value of the rect to be inserted

y2 number

The top right y value of the rect to be inserted

Returns:

A promise that resolves to a newly created array object.

Type
PDFNet.Obj

insertString(pos, value)

Inserts an Obj::Type::e_string object in the array.

Parameters:
Name Type Description
pos number

The location in the array to insert the object . The object is inserted before the specified location. The first element in an array has a pos of zero. If pos >= Array->Length(), appends obj to array.

value string

The value of the Obj::Type::e_string object to be inserted.

Returns:

A promise that resolves to a newly created string object.

Type
PDFNet.Obj

insertStringWithSize(pos, value, size)

Inserts an Obj::Type::e_string object in the array.

Parameters:
Name Type Description
pos number

The location in the array to insert the object . The object is inserted before the specified location. The first element in an array has a pos of zero. If pos >= Array->Length(), appends obj to array.

value string

The buffer used to set the value of the Obj::Type::e_string object to be inserted.

size number

The number of bytes to copy from the 'value' buffer parameter.

Returns:

A promise that resolves to a newly created string object.

Type
PDFNet.Obj

insertText(pos, t)

Inserts an Obj::Type::e_string object in the array.

Parameters:
Name Type Description
pos number

The location in the array to insert the object . The object is inserted before the specified location. The first element in an array has a pos of zero. If pos >= Array->Length(), appends obj to array.

t string

The value of the Obj::Type::e_string object to be inserted.

Returns:

A promise that resolves to a newly created string object.

Type
PDFNet.Obj

isArray()

Returns:

A promise that resolves to true if this is an Array, false otherwise.

Type
boolean

isBool()

Returns:

A promise that resolves to true if this is a Bool object, false otherwise.

Type
boolean

isContainer()

Returns:

A promise that resolves to true if this is a Container (a dictionary, array, or a stream), false otherwise.

Type
boolean

isDict()

Returns:

A promise that resolves to true if this is a dictionary (i.e. Dict), false otherwise.

Type
boolean

isEqual(to)

Parameters:
Name Type Description
to PDFNet.Obj

Obj to compare to

Returns:

A promise that resolves to true if two Obj's point to the same object. This method does not compare object content. For this operation use IsEqualValue() instead.

Type
boolean

isFree()

Returns:

A promise that resolves to true if the object is in use or is marked as free.

Type
boolean

isIndirect()

Returns:

A promise that resolves to true if this is Indirect object (i.e. object referenced in the cross-reference table), false otherwise.

Type
boolean

isLoaded()

Returns:

A promise that resolves to true if the object is loaded in memory.

Type
boolean

isMarked()

Returns:

A promise that resolves to true if the object is marked.

Type
boolean

isName()

Returns:

A promise that resolves to true if this is Name, false otherwise.

Type
boolean

isNull()

Returns:

A promise that resolves to true if this is a Null object, false otherwise.

Type
boolean

isNumber()

Returns:

A promise that resolves to true if this is a Number object, false otherwise.

Type
boolean

isStream()

Returns:

A promise that resolves to true if this is a Stream, false otherwise.

Type
boolean

isString()

Returns:

A promise that resolves to true if this is a Str (String) object, false otherwise.

Type
boolean

pushBack(input_obj)

Appends an existing Obj at the end of the array.

Parameters:
Name Type Description
input_obj PDFNet.Obj

The value to be inserted into the dictionary. If 'obj' is indirect (i.e. is a shared) object it will be inserted by reference, otherwise the object will be cloned and then appended.

Returns:

A promise that resolves to a newly appended object.

Type
PDFNet.Obj

pushBackArray()

Appends a new Obj::Type::e_array object at the end of the array.

Returns:

A promise that resolves to the new array object.

Type
PDFNet.Obj

pushBackBool(value)

Appends a new Obj::Type::e_bool object at the end of the array.

Parameters:
Name Type Description
value boolean

The value of the Obj::Type::e_bool object.

Returns:

A promise that resolves to the new boolean object.

Type
PDFNet.Obj

pushBackDict()

Appends a new Obj::Type::e_dict object at the end of the array.

Returns:

A promise that resolves to the new dictionary object.

Type
PDFNet.Obj

pushBackMatrix(mtx)

Appends an array of 6 numbers at the end of the array.

Parameters:
Name Type Description
mtx PDFNet.matrix2d

A matrix used to set the values in an array of six numbers. The resulting array will be then inserted in this array.

Returns:

A promise that resolves to a newly appended array object.

Type
PDFNet.Obj

pushBackName(name)

Appends a new Obj::Type::e_name object at the end of the array.

Parameters:
Name Type Description
name string

The value of the Obj::Type::e_name object.

Returns:

A promise that resolves to the new array object.

Type
PDFNet.Obj

pushBackNull()

Appends a new Obj::Type::e_null object at the end of the array.

Returns:

A promise that resolves to the new null object.

Type
PDFNet.Obj

pushBackNumber(value)

Appends a new Obj::Type::e_number object at the end of the array.

Parameters:
Name Type Description
value number

The value of the Obj::Type::e_number object.

Returns:

A promise that resolves to the new number object.

Type
PDFNet.Obj

pushBackRect(x1, y1, x2, y2)

Appends an array of 4 numbers at the end of the array.

Parameters:
Name Type Description
x1 number

The bottom left x value of the rect to be inserted

y1 number

The bottom left y value of the rect to be inserted

x2 number

The top right x value of the rect to be inserted

y2 number

The top right y value of the rect to be inserted

Returns:

A promise that resolves to a newly appended array object.

Type
PDFNet.Obj

pushBackString(value)

Appends a new Obj::Type::e_string object at the end of the array.

Parameters:
Name Type Description
value string

The value of the Obj::Type::e_string object.

Returns:

A promise that resolves to the new string object.

Type
PDFNet.Obj

pushBackStringWithSize(value, size)

Appends a new Obj::Type::e_string object at the end of the array.

Parameters:
Name Type Description
value string

The buffer used to set the value of the Obj::Type::e_string object to be inserted.

size number

The number of bytes to copy from the 'value' buffer parameter.

Returns:

A promise that resolves to the new string object.

Type
PDFNet.Obj

pushBackText(t)

Appends a new Obj::Type::e_string object at the end of the array.

Parameters:
Name Type Description
t string

The value of the Obj::Type::e_string object to be inserted.

Returns:

A promise that resolves to the new string object.

Type
PDFNet.Obj

put(key, input_obj)

Inserts a <key, Obj> pair in the dictionary.

Parameters:
Name Type Description
key string

The key of the value to set.

input_obj PDFNet.Obj

The value to be inserted into the dictionary. If 'obj' is indirect (i.e. is a shared) object it will be inserted by reference, otherwise the object will be cloned and then inserted into the dictionary.

Returns:

A promise that resolves to a newly inserted object.

Type
PDFNet.Obj

putArray(key)

Inserts a <key, Obj::Type::e_array> pair in the dictionary.

Parameters:
Name Type Description
key string

The key of the value to set.

Returns:

A promise that resolves to a newly created array object.

Type
PDFNet.Obj

putBool(key, value)

Inserts a <key, Obj::Type::e_bool> pair in the dictionary.

Parameters:
Name Type Description
key string

The key of the value to set.

value boolean

The value of the Obj::Type::e_bool object to be inserted into the dictionary.

Returns:

A promise that resolves to a newly created boolean object.

Type
PDFNet.Obj

putDict(key)

Inserts a <key, Obj::Type::e_dict> pair in the dictionary.

Parameters:
Name Type Description
key string

The key of the value to set.

Returns:

A promise that resolves to a newly created dictionary.

Type
PDFNet.Obj

putMatrix(key, mtx)

Inserts a <key, [a,b,c,d,h,v]> pair in the dictionary.

Parameters:
Name Type Description
key string

The key of the value to set.

mtx PDFNet.matrix2d

A matrix used to set the values in an array of six numbers. The resulting array will be inserted into the dictionary.

Returns:

A promise that resolves to a newly created array object.

Type
PDFNet.Obj

putName(key, name)

Inserts a <key, Obj::Type::e_name> pair in the dictionary.

Parameters:
Name Type Description
key string

The key of the value to set.

name string

The value of the Obj::Type::e_name object to be inserted into the dictionary.

Returns:

A promise that resolves to a newly created name object.

Type
PDFNet.Obj

putNull(key)

Inserts a <key, Obj::Type::e_null> pair in the dictionary.

Parameters:
Name Type Description
key string

The key of the value to set.


putNumber(key, value)

Inserts a <key, Obj::Type::e_number> pair in the dictionary.

Parameters:
Name Type Description
key string

The key of the value to set.

value number

The value of the Obj::Type::e_number object to be inserted into the dictionary.

Returns:

A promise that resolves to a newly created number object.

Type
PDFNet.Obj

putRect(key, x1, y1, x2, y2)

Inserts a <key, [x1,y1,x2,y2]> pair in the dictionary.

Parameters:
Name Type Description
key string

The key of the value to set.

x1 number

The bottom left x value of the rect to be inserted

y1 number

The bottom left y value of the rect to be inserted

x2 number

The top right x value of the rect to be inserted

y2 number

The top right y value of the rect to be inserted

Returns:

A promise that resolves to a newly created array object.

Type
PDFNet.Obj

putString(key, value)

Inserts a <key, Obj::Type::e_string> pair in the dictionary.

Parameters:
Name Type Description
key string

The key of the value to set.

value string

The value of the Obj::Type::e_string object to be inserted into the dictionary.

Returns:

A promise that resolves to a newly created string object.

Type
PDFNet.Obj

putStringWithSize(key, value, size)

Inserts a <key, Obj::Type::e_string> pair in the dictionary.

Parameters:
Name Type Description
key string

The key of the value to set.

value string

The buffer used to set the value of the Obj::Type::e_string object to be inserted into the dictionary.

size number

The number of bytes to copy from the 'value' buffer parameter.

Returns:

A promise that resolves to a newly created string object.

Type
PDFNet.Obj

putText(key, t)

Inserts a <key, Obj::Type::e_string> pair in the dictionary.

Parameters:
Name Type Description
key string

The key of the value to set.

t string

The value of the Obj::Type::e_string object to be inserted into the dictionary.

Returns:

A promise that resolves to a newly created string object.

Type
PDFNet.Obj

rename(old_key, new_key)

Change the key value of a dictionary entry. The key can't be renamed if another key with the same name already exists in the dictionary. In this case Rename returns false.

Parameters:
Name Type Description
old_key string

A string representing the key value to be changed.

new_key string

A string representing the key value that the old key is changed into.

Returns:

A promise that resolves to an unknown type


setBool(b)

Parameters:
Name Type Description
b boolean

bool value used to set Bool object.


setMark(mark)

Set the object mark. Mark is a boolean value that can be associated with every indirect object. This is especially useful when an object graph should be traversed and an operation should be performed on each node only once.

Parameters:
Name Type Description
mark boolean

boolean value that the object's mark should be set to.


setName(name)

Parameters:
Name Type Description
name string

value used to set Name object.


setNumber(n)

Parameters:
Name Type Description
n number

value used to set Number object.


setStreamData(data, data_size)

Parameters:
Name Type Description
data string
data_size number

setStreamDataWithFilter(data, data_size, filter_chain)

Parameters:
Name Type Description
data string
data_size number
filter_chain PDFNet.Filter

setString(value)

Parameters:
Name Type Description
value string

setUString(value)

Sets the string object value.

Parameters:
Name Type Description
value string

A Unicode string value.


size()

Returns:

A promise that resolves to the 'size' of the object. The definition of 'size' depends on the object type. In particular: For a dictionary or a stream object, the method will return the number of key/value pairs in the dictionary. For an array object the method will return the number of Obj entries in the array. For a string object the method will return the number of bytes in the string buffer. For any other object the method will always return 1.

Type
number

write(stream)

The function writes the Obj to the output stream

Parameters:
Name Type Description
stream PDFNet.FilterWriter

the input stream where the Obj will be written