new SDFDoc()
SDFDoc is a low-level document representing a graph of SDF::Obj nodes that
can be used to build higher-level document models such as PDF (Portable Document
Format) or FDF (Forms Document Format).
SDFDoc brings together document security, document utility methods, and all SDF
objects.
A SDF document can be created from scratch using a default constructor:
SDFDoc mydoc;
Obj trailer = mydoc.GetTrailer();
SDF document can be also created from an existing file (e.g. an external PDF document):
SDFDoc mydoc("in.pdf"); Obj trailer = mydoc.GetTrailer();or from a memory buffer or some other Filter/Stream such as a HTTP Filter connection:
MemoryFilter memory = .... SDFDoc mydoc(memory); Obj trailer = mydoc.GetTrailer();Finally SDF document can be accessed from a high-level PDF document as follows:
PDFDoc doc("in.pdf"); SDFDoc& mydoc = doc.GetSDFDoc(); Obj trailer = mydoc.GetTrailer();Note that the examples above used doc.GetTrailer() in order to access document trailer, the starting SDF object (root node) in every document. Following the trailer links, it is possible to visit all low-level objects in a document (e.g. all pages, outlines, fonts, etc). SDFDoc also provides utility methods used to import objects and object collections from one document to another. These methods can be useful for copy operations between documents such as a high-level page merge and document assembly.
Members
-
<static> SaveOptions
-
Properties:
Name Type Description e_incremental
number e_remove_unused
number e_hex_strings
number e_omit_xref
number e_linearized
number e_compatibility
number
Methods
-
applyCustomQuery(query)
-
Parameters:
Name Type Description query
object Returns:
- Type
- Promise.<any>
-
clearMarks()
-
Removes 'marked' flag from all objects in cross reference table.
Returns:
- Type
- Promise.<void>
-
createIndirectArray()
-
Used to create SDF/Cos indirect object. Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects they can be shared). Note: In C++ doc.CreateIndirect???(...) is equivalent to ???::CreateIndirect(...).
Returns:
A promise that resolves to an object of type: "PDFNet.Obj"- Type
- Promise.<Core.PDFNet.Obj>
-
createIndirectBool(value)
-
Used to create SDF/Cos indirect object. Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects they can be shared).
Parameters:
Name Type Description value
boolean indirect boolean to create. Note: In C++ doc.CreateIndirect???(...) is equivalent to ???::CreateIndirect(...). Returns:
A promise that resolves to an object of type: "PDFNet.Obj"- Type
- Promise.<Core.PDFNet.Obj>
-
createIndirectDict()
-
Returns:
A promise that resolves to an object of type: "PDFNet.Obj"- Type
- Promise.<Core.PDFNet.Obj>
-
createIndirectName(name)
-
Used to create SDF/Cos indirect object. Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects they can be shared).
Parameters:
Name Type Description name
string indirect const char* object to create. Note: In C++ doc.CreateIndirect???(...) is equivalent to ???::CreateIndirect(...). Returns:
A promise that resolves to an object of type: "PDFNet.Obj"- Type
- Promise.<Core.PDFNet.Obj>
-
createIndirectNull()
-
Returns:
A promise that resolves to an object of type: "PDFNet.Obj"- Type
- Promise.<Core.PDFNet.Obj>
-
createIndirectNumber(value)
-
Used to create SDF/Cos indirect object. Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects they can be shared).
Parameters:
Name Type Description value
number indirect boolean to create. Returns:
A promise that resolves to the created indirect object.- Type
- Promise.<Core.PDFNet.Obj>
-
createIndirectStream(data_buf, filter_chain)
-
Used to create SDF/Cos indirect object. Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects they can be shared).
Parameters:
Name Type Description data_buf
ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray indirect boolean to create. filter_chain
Core.PDFNet.Filter Returns:
A promise that resolves to the created indirect object. Note: After calling the following methods the filter object is invalidated and should not be used- Type
- Promise.<Core.PDFNet.Obj>
-
createIndirectStreamFromFilter(data [, filter_chain])
-
Note: After calling the following methods the filter object is invalidated and should not be used
Parameters:
Name Type Argument Description data
Core.PDFNet.FilterReader filter_chain
Core.PDFNet.Filter <optional>
Returns:
A promise that resolves to an object of type: "PDFNet.Obj"- Type
- Promise.<Core.PDFNet.Obj>
-
createIndirectString(buf_value)
-
Used to create SDF/Cos indirect object. Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects they can be shared).
Parameters:
Name Type Description buf_value
ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray indirect boolean to create. Returns:
A promise that resolves to the created indirect object.- Type
- Promise.<Core.PDFNet.Obj>
-
createIndirectStringFromUString(str)
-
Used to create SDF/Cos indirect object. Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects they can be shared).
Parameters:
Name Type Description str
string indirect boolean to create. Returns:
A promise that resolves to the created indirect object.- Type
- Promise.<Core.PDFNet.Obj>
-
createShallowCopy()
-
Copy Constructor
Returns:
A promise that resolves to an object of type: "PDFNet.SDFDoc"- Type
- Promise.<Core.PDFNet.SDFDoc>
-
enableDiskCaching(use_cache_flag)
-
A document uses a temporary file which is used to cache the contents of any new stream object created in the document (that is the default behavior).
Parameters:
Name Type Description use_cache_flag
boolean true to enable caching, false to disable caching. Use this function to enable or disable this feature dynamically. Returns:
- Type
- Promise.<void>
-
getFileName()
-
Returns:
A promise that resolves to the filename of the document if the document is loaded from disk, or empty string if the document is not yet saved or is loaded from a memory buffer.- Type
- Promise.<string>
-
getHeader()
-
Returns:
A promise that resolves to the header string identifying the document version to which the file conforms. For a file conforming to PDF version 1.4, the header should be %PDF-1.4. In general header strings have the following syntax: %AAA-N.n where AAA identifies document specification (such as PDF, FDF, PJTF etc), N is the major version and n is the minor version. The new header string can be set during a full save (see SDFDoc::Save()). For a document that is not serialized the function returns an empty string.- Type
- Promise.<string>
-
getHintStream()
-
Returns document's initial linearization hint stream if it is available.
Returns:
A promise that resolves to the linearization hint stream of the original document or NULL if the hint stream is not available.- Type
- Promise.<Core.PDFNet.Obj>
-
getLinearizationDict()
-
Returns document's initial linearization dictionary if it is available.
Returns:
A promise that resolves to the linearization dictionary of the original document or NULL if the dictionary is not available.- Type
- Promise.<Core.PDFNet.Obj>
-
getObj(obj_num)
-
Parameters:
Name Type Description obj_num
number object number of the object to retrieve. Returns:
A promise that resolves to the latest version of the object matching specified object number.- Type
- Promise.<Core.PDFNet.Obj>
-
getSecurityHandler()
-
Returns:
A promise that resolves to currently selected SecurityHandler. Note: InitSecurityHandler() should be called before GetSecurityHandler() in order to initialize the handler. Note: Returned security handler can be modified in order to change the security settings of the existing document. Changes to the current handler will not invalidate the access to the original file and will take effect during document Save(). Note: If the security handler is modified, document will perform a full save even if e_incremental was given as a flag in Save() method.- Type
- Promise.<Core.PDFNet.SecurityHandler>
-
getTrailer()
-
Returns:
A promise that resolves to A dictionary representing the root of the document (i.e. a document trailer dictionary)- Type
- Promise.<Core.PDFNet.Obj>
-
hasRepairedXRef()
-
Checks whether or not the underlying file has an XRef table that had to be repaired when the file was opened. If the document had an invalid XRef table when opened, PDFNet will have repaired the XRef table for its working representation of the document.
Returns:
A promise that resolves to true if document was found to be corrupted, and was repaired, during opening and has not been saved since. Note: If this function returns true, it is not possible to incrementally save the document (see http://www.pdftron.com/kb_corrupt_xref)- Type
- Promise.<boolean>
-
importObj(obj, deep_copy)
-
Parameters:
Name Type Description obj
Core.PDFNet.Obj an object to import. deep_copy
boolean a boolean indicating whether to perform a deep or shallow copy. In case of shallow copy all indirect references will be set to null. If the object belongs to a document the function will perform deep or shallow clone depending whether deep_copy flag was specified. If the object does not belong to any document ImportObj does not take the object ownership. ImportObj copies the source object and it is users responsibility to delete free objects. Returns:
A promise that resolves to a pointer to the root indirect object in this document- Type
- Promise.<Core.PDFNet.Obj>
-
importObjsWithExcludeList(obj_list, exclude_list)
-
The function performs a deep copy of all objects specified in the 'obj_list'. If objects in the list are directly or indirectly referring to the same object/s, only one copy of the shared object/s will be copied. Therefore, unlike repeated calls to ImportObj, this method will import only one copy of shared objects (objects representing an intersection of graphs specified through 'obj_list' of root pointers. Note: All object in the import list must belong to the same source document. Note: The function does not perform the shallow copy since ImportObj() can be used instead.
Parameters:
Name Type Description obj_list
Array.<Core.PDFNet.Obj> a list of root objects to import. All directly or indirectly objects will be imported as well. exclude_list
Array.<Core.PDFNet.Obj> a list of objects to not include in the deep copy. Returns:
A promise that resolves to a list of imported root objects in this document.- Type
- Promise.<Core.PDFNet.Obj>
-
initSecurityHandler()
-
Initializes document's SecurityHandler. This version of InitSecurityHandler() works with Standard and Custom PDF security and can be used in situations where the password is obtained dynamically via user feedback. See EncTest sample for example code. This function should be called immediately after an encrypted document is opened. The function does not have any side effects on documents that are not encrypted. If the security handler was successfully initialized it can be later obtained using GetSecurityHandler() method.
Returns:
A promise that resolves to true if the SecurityHandler was successfully initialized (this may include authentication data collection, verification etc.), false otherwise.- Type
- Promise.<boolean>
-
initStdSecurityHandler(password)
-
Initializes document's SecurityHandler using the supplied password. This version of InitSecurityHandler() assumes that document uses Standard security and that a password is specified directly. This function should be called immediately after an encrypted document is opened. The function does not have any side effects on documents that are not encrypted. If the security handler was successfully initialized, it can be later obtained using GetSecurityHandler() method.
Parameters:
Name Type Description password
string Specifies the password used to open the document without any user feedback. Returns:
A promise that resolves to true if the given password successfully unlocked the document, false otherwise.- Type
- Promise.<boolean>
-
initStdSecurityHandlerUString(password)
-
Initializes document's SecurityHandler using the supplied password. This version of InitSecurityHandler() assumes that document uses Standard security and that a password is specified directly. This function should be called immediately after an encrypted document is opened. The function does not have any side effects on documents that are not encrypted. If the security handler was successfully initialized, it can be later obtained using GetSecurityHandler() method.
Parameters:
Name Type Description password
string Specifies the password used to open the document without any user feedback. If you would like to dynamically obtain the password, you need to derive a custom class from StdSecurityHandler() and use InitSecurityHandler() without any parameters. See EncTest sample for example code. Returns:
A promise that resolves to true if the given password successfully unlocked the document, false otherwise.- Type
- Promise.<boolean>
-
isEncrypted()
-
Returns:
A promise that resolves to true if the document is/was originally encrypted false otherwise.- Type
- Promise.<boolean>
-
isFullSaveRequired()
-
Returns:
A promise that resolves to true if the document requires full save.- Type
- Promise.<boolean>
-
isLinearized()
-
Call this function to determine whether the document is represented in linearized (fast web view) format.
Returns:
A promise that resolves to true if document is stored in fast web view format, false otherwise. Note: any changes to the document can invalidate linearization. The function will return 'true' only if the original document is linearized and if it is not modified. In order to provide good performance over relatively slow communication links, PDFNet can generate PDF documents with linearized objects and hint tables that can allow a PDF viewer application to download and view one page of a PDF file at a time, rather than requiring the entire file (including fonts and images) to be downloaded before any of it can be viewed. To save a document in linearized (fast web view) format you only need to pass 'SDFDoc.SaveOptions.e_linearized' flag in the Save method.- Type
- Promise.<boolean>
-
isModified()
-
Returns:
A promise that resolves to true if document was modified, false otherwise- Type
- Promise.<boolean>
-
lock()
-
Locks the document to prevent competing threads from accessing the document at the same time. Threads attempting to access the document will wait in suspended state until the thread that owns the lock calls doc.Unlock().
Returns:
- Type
- Promise.<void>
-
lockRead()
-
Locks the document to prevent competing write threads (using Lock()) from accessing the document at the same time. Other reader threads however, will be allowed to access the document. Threads attempting to obtain write access to the document will wait in suspended state until the thread that owns the lock calls doc.UnlockRead(). Note: To avoid deadlocks obtaining a write lock while holding a read lock is not permitted and will throw an exception. If this situation is encountered please either unlock the read lock before the write lock is obtained or acquire a write lock (rather than read lock) in the first place.
Returns:
- Type
- Promise.<void>
-
releaseFileHandles()
-
Returns:
- Type
- Promise.<void>
-
removeSecurity()
-
This function removes document security.
Returns:
- Type
- Promise.<void>
-
saveMemory(flags, header)
-
Saves the document to a memory buffer.
Parameters:
Name Type Description flags
number A bit field composed of an OR of the SDFDoc::SaveOptions values. Note that this method ignores e_incremental flag. header
string File header. A new file header is set only during full save. Returns:
A promise that resolves to the buffer containing the serialized version of the document. Note: Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.- Type
- Promise.<Uint8Array>
-
saveStream(stream, flags, header)
-
Saves the document to a stream.
Parameters:
Name Type Description stream
Core.PDFNet.Filter The output stream where to write data. flags
number A bit field composed of an OR of the SDFDoc::SaveOptions values. header
string File header. A new file header is set only during full save. See also GetHeader() Note: Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save. Returns:
- Type
- Promise.<void>
-
setSecurityHandler(handler)
-
The function sets a new SecurityHandler as the current security handler.
Parameters:
Name Type Description handler
Core.PDFNet.SecurityHandler new SecurityHandler Note: Setting a new security handler will not invalidate the access to the original file and will take effect during document Save(). Note: If the security handler is modified, document will perform a full save even if e_incremental was given as a flag in Save() method. Returns:
- Type
- Promise.<void>
-
swap(obj_num1, obj_num2)
-
Sometimes it is desirable to modify all indirect references to a given indirect object. It would be inefficient to manually search for all indirect references to a given indirect object. A more efficient and less error prone method is to replace the indirect object in the cross reference table with a new object. This way the object that is referred to is modified (or replaced) and indirect references do not have to be changed.
Parameters:
Name Type Description obj_num1
number object number of first object to be swapped. obj_num2
number object number of second object to be swapped. Returns:
- Type
- Promise.<void>
-
tryLock()
-
Try locking the document.
Returns:
A promise that resolves to true if the document is locked for multi-threaded access, false otherwise.- Type
- Promise.<boolean>
-
tryLockRead()
-
Tries to obtain a read lock the document and returns true if the lock was successfully acquired
Returns:
A promise that resolves to true if the document is locked for multi-threaded access, false otherwise.- Type
- Promise.<boolean>
-
unlock()
-
Removes the lock from the document.
Returns:
- Type
- Promise.<void>
-
unlockRead()
-
Removes the lock from the document.
Returns:
- Type
- Promise.<void>
-
xRefSize()
-
Returns:
A promise that resolves to The size of cross reference table- Type
- Promise.<number>