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).

Members


<static> Type

Properties:
Name Type Description
e_null number
e_bool number
e_number number
e_name number
e_string number
e_dict number
e_array number
e_stream number

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.
Returns:
Type
Promise.<void>

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.
Returns:
Type
Promise.<void>

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.
Returns:
Type
Promise.<void>

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
Promise.<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
Promise.<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
Promise.<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
Promise.<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: "PDFNet.Obj"
Type
Promise.<PDFNet.Obj>

getBool()

Returns:
A promise that resolves to bool value if this is Bool.
Type
Promise.<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
Promise.<number>

getDecodedStream()

Returns:
A promise that resolves to A filter to the decoded stream
Type
Promise.<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
Promise.<PDFNet.DictIterator>

getDoc()

Returns:
A promise that resolves to the document to which this object belongs.
Type
Promise.<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
Promise.<number>

getName()

Returns:
A promise that resolves to string representing the Name object.
Type
Promise.<string>

getNumber()

Returns:
A promise that resolves to value, if this is Number.
Type
Promise.<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
Promise.<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
Promise.<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
Promise.<PDFNet.Filter>

getRawStreamLength()

Returns:
A promise that resolves to the length of the raw/encoded stream equal to the Length parameter
Type
Promise.<number>

getType()

Returns:
A promise that resolves to the object type.
Type
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<PDFNet.Obj>

isArray()

Returns:
A promise that resolves to true if this is an Array, false otherwise.
Type
Promise.<boolean>

isBool()

Returns:
A promise that resolves to true if this is a Bool object, false otherwise.
Type
Promise.<boolean>

isContainer()

Returns:
A promise that resolves to true if this is a Container (a dictionary, array, or a stream), false otherwise.
Type
Promise.<boolean>

isDict()

Returns:
A promise that resolves to true if this is a dictionary (i.e. Dict), false otherwise.
Type
Promise.<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
Promise.<boolean>

isFree()

Returns:
A promise that resolves to true if the object is in use or is marked as free.
Type
Promise.<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
Promise.<boolean>

isLoaded()

Returns:
A promise that resolves to true if the object is loaded in memory.
Type
Promise.<boolean>

isMarked()

Returns:
A promise that resolves to true if the object is marked.
Type
Promise.<boolean>

isName()

Returns:
A promise that resolves to true if this is Name, false otherwise.
Type
Promise.<boolean>

isNull()

Returns:
A promise that resolves to true if this is a Null object, false otherwise.
Type
Promise.<boolean>

isNumber()

Returns:
A promise that resolves to true if this is a Number object, false otherwise.
Type
Promise.<boolean>

isStream()

Returns:
A promise that resolves to true if this is a Stream, false otherwise.
Type
Promise.<boolean>

isString()

Returns:
A promise that resolves to true if this is a Str (String) object, false otherwise.
Type
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<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
Promise.<PDFNet.Obj>

put(key, input_obj)

Inserts a 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
Promise.<PDFNet.Obj>

putArray(key)

Inserts a 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
Promise.<PDFNet.Obj>

putBool(key, value)

Inserts a 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
Promise.<PDFNet.Obj>

putDict(key)

Inserts a 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
Promise.<PDFNet.Obj>

putMatrix(key, mtx)

Inserts a 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
Promise.<PDFNet.Obj>

putName(key, name)

Inserts a 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
Promise.<PDFNet.Obj>

putNull(key)

Inserts a pair in the dictionary.
Parameters:
Name Type Description
key string The key of the value to set.
Returns:
Type
Promise.<void>

putNumber(key, value)

Inserts a 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
Promise.<PDFNet.Obj>

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

Inserts a 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
Promise.<PDFNet.Obj>

putString(key, value)

Inserts a 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
Promise.<PDFNet.Obj>

putStringWithSize(key, value, size)

Inserts a 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
Promise.<PDFNet.Obj>

putText(key, t)

Inserts a 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
Promise.<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 object of type: "boolean"
Type
Promise.<boolean>

setBool(b)

Parameters:
Name Type Description
b boolean bool value used to set Bool object.
Returns:
Type
Promise.<void>

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.
Returns:
Type
Promise.<void>

setName(name)

Parameters:
Name Type Description
name string value used to set Name object.
Returns:
Type
Promise.<void>

setNumber(n)

Parameters:
Name Type Description
n number value used to set Number object.
Returns:
Type
Promise.<void>

setStreamData(data, data_size)

Parameters:
Name Type Description
data string
data_size number
Returns:
Type
Promise.<void>

setStreamDataWithFilter(data, data_size [, filter_chain])

Parameters:
Name Type Argument Description
data string
data_size number
filter_chain PDFNet.Filter <optional>
Returns:
Type
Promise.<void>

setString(value)

Parameters:
Name Type Description
value string
Returns:
Type
Promise.<void>

setUString(value)

Sets the string object value.
Parameters:
Name Type Description
value string A Unicode string value.
Returns:
Type
Promise.<void>

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
Promise.<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
Returns:
Type
Promise.<void>