Class: Obj

Core.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 Core.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. Note: A dictionary entry whose value is Obj::Null is equivalent to an absent entry.
 DictIterator itr = info_dict.Find("Info");	
 if (itr.HasNext()) {
   Obj info = itr.Value();
   if (info.IsDict())
     info.PutString("Producer", "PDFTron PDFNet SDK");
}
Type
Promise.<Core.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. Note: A dictionary entry whose value is Obj::Null is equivalent to an absent entry.
Type
Promise.<Core.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.<Core.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. Note: Not all SDF/Cos String objects are used to represent 'PDF Text'. PDF Reference indicates (on a case by case basis ) where an SDF/Cos String object can be used as 'PDF Text'.
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.<Core.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. Note: if SDF/Cos String object is represented as 'PDF Text' (Section 3.8.1 'Text Strings' in PDF Reference) you can use GetAsPDFText method to obtain Unicode representation of the string. Note: use Size() member function in order to obtain the number of bytes in string buffer.
Type
Promise.<number>

getDecodedStream()

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

getDoc()

Returns:
A promise that resolves to the document to which this object belongs. Note: this method can be invoked on any Obj.
Type
Promise.<Core.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. Note: this method can be invoked on any Obj.
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. Note: this method can be invoked on any Obj.
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. Note: this method can be invoked on any Obj.
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.<Core.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. Note: this method can be invoked on any Obj.
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 Core.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.<Core.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.<Core.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.<Core.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.<Core.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 Core.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.<Core.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.<Core.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.<Core.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.<Core.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.<Core.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.<Core.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. Note: InsertText will create the string object as a 'PDF Text' object.
Returns:
A promise that resolves to a newly created string object.
Type
Promise.<Core.PDFNet.Obj>

isArray()

Returns:
A promise that resolves to true if this is an Array, false otherwise. Note: this method can be invoked on any Obj.
Type
Promise.<boolean>

isBool()

Returns:
A promise that resolves to true if this is a Bool object, false otherwise. Note: this method can be invoked on any Obj.
Type
Promise.<boolean>

isContainer()

Returns:
A promise that resolves to true if this is a Container (a dictionary, array, or a stream), false otherwise. Note: this method can be invoked on any Obj.
Type
Promise.<boolean>

isDict()

Returns:
A promise that resolves to true if this is a dictionary (i.e. Dict), false otherwise. Note: this method can be invoked on any Obj.
Type
Promise.<boolean>

isEqual(to)

Parameters:
Name Type Description
to Core.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. Note: this method can be invoked on any Obj.
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. Note: this method can be invoked on any Obj.
Type
Promise.<boolean>

isLoaded()

Returns:
A promise that resolves to true if the object is loaded in memory. Note: this method can be invoked on any Obj.
Type
Promise.<boolean>

isMarked()

Returns:
A promise that resolves to true if the object is marked. Note: this method can be invoked on any Obj.
Type
Promise.<boolean>

isName()

Returns:
A promise that resolves to true if this is Name, false otherwise. Note: this method can be invoked on any Obj.
Type
Promise.<boolean>

isNull()

Returns:
A promise that resolves to true if this is a Null object, false otherwise. Note: this method can be invoked on any Obj.
Type
Promise.<boolean>

isNumber()

Returns:
A promise that resolves to true if this is a Number object, false otherwise. Note: this method can be invoked on any Obj.
Type
Promise.<boolean>

isStream()

Returns:
A promise that resolves to true if this is a Stream, false otherwise. Note: this method can be invoked on any Obj.
Type
Promise.<boolean>

isString()

Returns:
A promise that resolves to true if this is a Str (String) object, false otherwise. Note: this method can be invoked on any Obj.
Type
Promise.<boolean>

pushBack(input_obj)

Appends an existing Obj at the end of the array.
Parameters:
Name Type Description
input_obj Core.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.<Core.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.<Core.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.<Core.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.<Core.PDFNet.Obj>

pushBackMatrix(mtx)

Appends an array of 6 numbers at the end of the array.
Parameters:
Name Type Description
mtx Core.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.<Core.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.<Core.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.<Core.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.<Core.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.<Core.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.<Core.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. Note: InsertText will create the string object as a 'PDF Text' object.
Returns:
A promise that resolves to the new string object.
Type
Promise.<Core.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 Core.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.<Core.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. Note: If a dictionary already contains an entry with the same key, the old entry will be deleted and all DictIterators to this entry will be invalidated.
Type
Promise.<Core.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. Note: If a dictionary already contains an entry with the same key, the old entry will be deleted and all DictIterators to this entry will be invalidated.
Type
Promise.<Core.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. Note: If a dictionary already contains an entry with the same key, the old entry will be deleted and all DictIterators to this entry will be invalidated.
Type
Promise.<Core.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 Core.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. Note: If a dictionary already contains an entry with the same key, the old entry will be deleted and all DictIterators to this entry will be invalidated.
Type
Promise.<Core.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. Note: If a dictionary already contains an entry with the same key, the old entry will be deleted and all DictIterators to this entry will be invalidated.
Type
Promise.<Core.PDFNet.Obj>

putNull(key)

Inserts a pair in the dictionary.
Parameters:
Name Type Description
key string The key of the value to set. Note: The effect of calling this method is essentially the same as dict.Erase(key) .
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. Note: If a dictionary already contains an entry with the same key, the old entry will be deleted and all DictIterators to this entry will be invalidated.
Type
Promise.<Core.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. Note: If a dictionary already contains an entry with the same key, the old entry will be deleted and all DictIterators to this entry will be invalidated.
Type
Promise.<Core.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. Note: If a dictionary already contains an entry with the same key, the old entry will be deleted and all DictIterators to this entry will be invalidated.
Type
Promise.<Core.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. Note: PutText will create the string object as a 'PDF Text' object.
Returns:
A promise that resolves to a newly created string object. Note: If a dictionary already contains an entry with the same key, the old entry will be deleted and all DictIterators to this entry will be invalidated.
Type
Promise.<Core.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. Note: this method can be invoked on any Obj.
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_buf)

Parameters:
Name Type Description
data_buf ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray
Returns:
Type
Promise.<void>

setStreamDataWithFilter(data_buf, filter_chain)

allows to replace the content stream with a new one without creating a new object
Parameters:
Name Type Description
data_buf ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray
filter_chain Core.PDFNet.Filter
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. Note: this method can be invoked on any Obj.
Type
Promise.<number>

write(stream)

The function writes the Obj to the output stream
Parameters:
Name Type Description
stream Core.PDFNet.FilterWriter the input stream where the Obj will be written Note: this method can be invoked on any Obj.
Returns:
Type
Promise.<void>