# Class: SDFDoc

## PDFNet. SDFDoc

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

### Methods

#### clearMarks()

  Removes 'marked' flag from all objects in cross reference table.

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

  ##### Returns:

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

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

  ##### Returns:

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

  Type
    PDFNet.Obj

#### createIndirectDict()

  ##### Returns:

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

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

  ##### Returns:

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

  Type
    PDFNet.Obj

#### createIndirectNull()

  ##### Returns:

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

  Type
    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:

  {Obj} A promise that resolves to the created indirect object.

  Type
    PDFNet.Obj

#### createIndirectStream(data, data_size, filter_chain)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `data` | string |
  `data_size` | number |
  `filter_chain` | PDFNet.Filter |

  ##### Returns:

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

  Type
    PDFNet.Obj

#### createIndirectStreamFromFilter(data, filter_chain)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `data` | PDFNet.FilterReader |
  `filter_chain` | PDFNet.Filter |

  ##### Returns:

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

  Type
    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` | Array | indirect boolean to create.

  ##### Returns:

  {Obj} A promise that resolves to the created indirect object.

  Type
    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:

  {Obj} A promise that resolves to the created indirect object.

  Type
    PDFNet.Obj

#### createShallowCopy()

  Copy Constructor

  ##### Returns:

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

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

#### 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
    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
    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
    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
    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
    PDFNet.Obj

#### getSecurityHandler()

  ##### Returns:

  A promise that resolves to currently selected SecurityHandler.

  Type
    PDFNet.SecurityHandler

#### getTrailer()

  ##### Returns:

  A promise that resolves to A dictionary representing the root of the document (i.e. a document trailer dictionary)

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

  Type
    boolean

#### importObj(obj, deep_copy)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `obj` | 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
    PDFNet.Obj

#### initSecurityHandler(custom_data)

  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.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `custom_data` | UNKNOWNTYPE | An optional parameter used to specify custom data that should be passed in SecurityHandler::Initialize() callback.

  ##### Returns:

  A promise that resolves to true if the SecurityHandler was successfully initialized (this may include authentication data collection, verification etc.), false otherwise.

  Type
    boolean

#### initStdSecurityHandler(password, password_sz)

  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.
  `password_sz` | number | An optional parameter used to specify the size of the password buffer, in bytes. If the 'password_sz' is 0, or if the parameter is not specified, the function assumes that the string is null terminated.

  ##### Returns:

  A promise that resolves to true if the given password successfully unlocked the document, false otherwise.

  Type
    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
    boolean

#### isEncrypted()

  ##### Returns:

  A promise that resolves to true if the document is/was originally encrypted false otherwise.

  Type
    boolean

#### isFullSaveRequired()

  ##### Returns:

  A promise that resolves to true if the document requires full save.

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

  Type
    boolean

#### isModified()

  ##### Returns:

  A promise that resolves to true if document was modified, false otherwise

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

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

#### releaseFileHandles()

#### removeSecurity()

  This function removes document security.

#### saveMemory(flags, header)

  [Documentation Not Yet Added]

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `flags` | string | (generated documentation)
  `header` | number | (generated documentation)

#### saveStream(stream, flags, header)

  Saves the document to a stream.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `stream` | 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 | Fileheader header. A new file header is set only during full save. See also GetHeader()

#### setSecurityHandler(handler)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `handler` | PDFNet.SecurityHandler |

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

#### tryLock()

  Try locking the document.

  ##### Returns:

  A promise that resolves to true if the document is locked for multi-threaded access, false otherwise.

  Type
    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
    boolean

#### unlock()

  Removes the lock from the document.

#### unlockRead()

  Removes the lock from the document.

#### xRefSize()

  ##### Returns:

  A promise that resolves to The size of cross reference table

  Type
    number

#### Search results