Summary: Nested Classes | Constants | Ctors | Methods | Inherited Methods | [Expand All]
public class

# SDFDoc

extends Doc
implements AutoCloseable

java.lang.Object
↳ | com.pdftron.sdf.Doc
| ↳ | com.pdftron.sdf.SDFDoc

## Class Overview

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). SDF Doc 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 = new SDFDoc(); Obj trailer = mydoc.getTrailer(); SDF document can be also created from an existing file (e.g. an external PDF document): `SDFDoc mydoc = new SDFDoc("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 = new SDFDoc(memory); Obj trailer = mydoc.getTrailer();` Finally SDF document can be accessed from a high-level PDF document as follows: `PDFDoc doc = new PDFDoc("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.

## Summary

Nested Classes
enum | SDFDoc.SaveMode |

Constants
int | e_compatibility | This constant is deprecated. use `COMPATIBILITY` instead.
int | e_hex_strings | This constant is deprecated. use `HEX_STRINGS` instead.
int | e_incremental | This constant is deprecated. use `INCREMENTAL` instead.
int | e_linearized | This constant is deprecated. use `LINEARIZED` instead.
int | e_omit_xref | This constant is deprecated. use `OMIT_XREF` instead.
int | e_remove_unused | This constant is deprecated. use `REMOVE_UNUSED` instead.

Public Constructors
| SDFDoc() Default constructor.
| SDFDoc(String filepath) Open a SDF/Cos document from a file.
| SDFDoc(Filter stream) Open a SDF/Cos document from a Filter (i.e.
| SDFDoc(byte[] buf) Open a SDF/Cos document from a memory buffer.
| SDFDoc(InputStream stream) Instantiates a new SDFDoc from stream.
| SDFDoc(InputStream stream, int size) Instantiates a new SDFDoc from stream with specified size.

Public Methods
static SDFDoc | __Create(long impl, Object ref)
long | __GetHandle()
Object | __GetRefHandle()
void | __SetRef(Object ref)
boolean | canSaveToPath(String path, SDFDoc.SaveMode saveMode) Checks if a path is valid for a planned save operation
boolean | canSaveToPath(String path, long flags) This method is deprecated. use `canSaveToPath(String, SaveMode)` instead. Checks if a path is valid for a planned save operation
void | clearMarks() Removes 'marked' flag from all objects in cross reference table.
void | close() Close SDFDoc and release resources Frees the native memory of the object.
Obj | createIndirectArray() Create an indirect array.
Obj | createIndirectBool(boolean value) Create an indirect boolean
Obj | createIndirectDict() Create an indirect dictionary
Obj | createIndirectName(String name) The following list of methods is used to create SDF/Cos indirect objects.
Obj | createIndirectNull() Create an indirect null
Obj | createIndirectNumber(double value) Create an indirect number.
Obj | createIndirectStream(byte[] data) Create an indirect stream from buffer
Obj | createIndirectStream(FilterReader data) Create an indirect stream from FilterReader
Obj | createIndirectStream(byte[] data, Filter filter_chain) Create an indirect stream
Obj | createIndirectStream(FilterReader data, Filter filter_chain) Create an indirect stream from FilterReader
Obj | createIndirectString(byte[] value) Create an indirect string.
Obj | createIndirectString(String str) Create an indirect string.
void | enableDiskCaching(boolean use_cache) Enable or disable disk caching feature Note: 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).
String | getFileName() Get SDFDoc filename
String | getHeader() Get the file header.
Obj | getHintStream() Get document's initial linearization hint stream if it is available.
Obj | getLinearizationDict() Get document's initial linearization dictionary if it is available.
Obj | getObj(long obj_num) Get the Obj with specified object number
SecurityHandler | getSecurityHandler() Get the security handler.
Obj | getTrailer() Get root of the document as Obj
boolean | hasRepairedXRef() Checks whether or not the underlying file has an XRef table that had to be repaired when the file was opened.
Obj | importObj(Obj obj, boolean deep_copy) Import obj to SDFDoc Note: If the object belongs to a document the function will perform deep or shallow clone depending whether deep_copy flag was specified.
Obj[] | importObjs(Obj[] obj_list, Obj[] exclusion_list) The function performs a deep copy of all objects specified in the 'obj_list'.
Obj[] | importObjs(Obj[] obj_list) The function performs a deep copy of all objects specified in the 'obj_list'.
boolean | initSecurityHandler(Object custom_data) Initializes document's SecurityHandler.
boolean | initSecurityHandler() Initializes document's SecurityHandler.
boolean | initStdSecurityHandler(byte[] passwordBuffer) Initializes document's SecurityHandler using the supplied password.
boolean | initStdSecurityHandler(String password) Initializes document's SecurityHandler using the supplied password.
boolean | isEncrypted() Checks if SDFDoc is encrypted.
boolean | isFullSaveRequired() Checks if is full save required.
boolean | isLinearized() Call this function to determine whether the document is represented in linearized (fast web view) format.
boolean | isModified() Checks if SDFDoc is modified.
void | lock() Locks the document to prevent competing threads from accessiong the document at the same time.
void | lockRead() Locks the document to prevent competing write threads (using lock()) from accessing the document at the same time.
void | removeSecurity() Removes all security from SDFDoc.
void | save(String path, SDFDoc.SaveMode saveMode, ProgressMonitor progress, String header) Saves the document to a file.
void | save(OutputStream stream, SDFDoc.SaveMode saveMode, ProgressMonitor progress, String header, int size) Save SDFDoc to output stream - Save will modify the SDFDoc object's internal representation.
void | save(OutputStream stream, long flags, ProgressMonitor progress, String header, int size) This method is deprecated. use `save(OutputStream, SaveMode, ProgressMonitor, String, int)` instead. Save SDFDoc to output stream - Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.
byte[] | save(long flags, ProgressMonitor progress, String header) This method is deprecated. use `save(SaveMode, ProgressMonitor, String)` instead. Saves the document to a memory buffer. - Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.
void | save(String path, long flags, ProgressMonitor progress, String header) This method is deprecated. use `save(String, SaveMode, ProgressMonitor, String)` instead. Saves the document to a file. If a full save is requested to the original path, the file is saved to a file system-determined temporary file, the old file is deleted, and the temporary file is renamed to path. A full save with remove unused or linearization option may re-arrange object in the cross reference table. Therefore all pointers and references to document objects and resources should be re acquired in order to continue document editing. In order to use incremental save the specified path must match original path and e_incremental flag bit should be set. Note: - Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save. Note: - If the original pdf has a corrupt xref table (see HasRepairedXref or http://www.pdftron.com/kb_corrupt_xref), then it can not be saved using the e_incremental flag.
byte[] | save(SDFDoc.SaveMode saveMode, ProgressMonitor progress, String header) Saves the document to a memory buffer.
void | save(OutputStream stream, long flags, ProgressMonitor progress, String header) This method is deprecated. use `save(OutputStream, SaveMode, ProgressMonitor, String)` instead. Save SDFDoc to output stream - Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.
void | save(OutputStream stream, SDFDoc.SaveMode saveMode, ProgressMonitor progress, String header) Save SDFDoc to output stream - Save will modify the SDFDoc object's internal representation.
void | setSecurityHandler(SecurityHandler handler) The function sets a new SecurityHandler as the current security handler.
void | swap(long obj_num1, long obj_num2) Sometimes it is desirable to modify all indirect references to a given indirect object.
boolean | timedLock(int milliseconds) Try locking the document, waiting no longer than specified number of milliseconds.
boolean | timedLockRead(int milliseconds) Tries to obtain a read lock the document for <milliseconds> duration, and returns true if the lock was successfully acquired
boolean | tryLockRead() Try obtaining a read lock on the document in non-blocking manner.
void | unlock() Removes the lock from the document.
void | unlockRead() Removes the read lock from the document.
long | xRefSize() Get size of the cross reference table

[Expand] Inherited Methods
From class com.pdftron.sdf.Doc
long | __GetHandle()
From class java.lang.Object
boolean | equals(Object arg0)
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)
final void | wait()
From interface java.lang.AutoCloseable
abstract void | close()

## Constants

#### public static final int e_compatibility

This constant is deprecated.
use `COMPATIBILITY` instead.

Saves the document in a manner that maximizes compatibility with older PDF consumers (e.g. the file will not use object and compressed xref streams).

Constant Value: 32 (0x00000020)

#### public static final int e_hex_strings

This constant is deprecated.
use `HEX_STRINGS` instead.

Save all string in hexadecimal format.

Constant Value: 4 (0x00000004)

#### public static final int e_incremental

This constant is deprecated.
use `INCREMENTAL` instead.

Save the document using incremental mode.

Constant Value: 1 (0x00000001)

#### public static final int e_linearized

This constant is deprecated.
use `LINEARIZED` instead.

Save the document in linearized (fast web-view) format. Requires full save.

Constant Value: 16 (0x00000010)

#### public static final int e_omit_xref

This constant is deprecated.
use `OMIT_XREF` instead.

Do not save cross-reference table

Constant Value: 8 (0x00000008)

#### public static final int e_remove_unused

This constant is deprecated.
use `REMOVE_UNUSED` instead.

Remove unused objects. Requires full save.

Constant Value: 2 (0x00000002)

## Public Constructors

#### public SDFDoc ()

Default constructor. Creates a new document. The new document contains only trailer and Info dictionary. To build the rest of the document get document's root dictionary using GetTrailer() and populate it with new key/value pairs.

##### Throws

PDFNetException |

#### public SDFDoc (String filepath)

Open a SDF/Cos document from a file.

Note: Make sure to call InitStdSecurityHandler() or InitSecurityHandler() after SDFDoc(...) in case the document is encrypted.

##### Parameters

filepath | - path name to the file.

##### Throws

PDFNetException |

#### public SDFDoc (Filter stream)

Open a SDF/Cos document from a Filter (i.e. a data stream) object.

Note: if the input stream doesn't support Seek() operation the document will load whole data stream in memory before parsing. In case of linearized PDF, the document may be parsed on-the-fly while it is being loaded in memory. Note that since StdFile implements Seek() interface, the document does not have to be fully in memory before it is used.

Make sure to call InitStdSecurityHandler() or InitSecurityHandler() after SDFDoc(...) in case the document is encrypted.

##### Parameters

stream | - input stream containing a serialized document. The input stream may be a random-access file, memory buffer, slow HTTP connection etc.

##### Throws

PDFNetException |

#### public SDFDoc (byte[] buf)

Open a SDF/Cos document from a memory buffer.

Note: the document should be fully loaded in the memory buffer.

the buffer ownership is not transfered to the Document so the user should clean-up if necessary.

Make sure to call InitStdSecurityHandler() or InitSecurityHandler() after SDFDoc(...) in case the document is encrypted.

##### Parameters

buf | - a memory buffer containing the serialized document

##### Throws

PDFNetException |

#### public SDFDoc (InputStream stream)

Instantiates a new SDFDoc from stream.

##### Parameters

stream | the input stream to create SDFDoc from

##### Throws

| PDFNetException
IOException | Signals that an I/O exception has occurred.
PDFNetException |

#### public SDFDoc (InputStream stream, int size)

Instantiates a new SDFDoc from stream with specified size.

##### Parameters

stream | the input stream to create SDFDoc from
size | the size

##### Throws

| PDFNetException
IOException | Signals that an I/O exception has occurred.
PDFNetException |

## Public Methods

#### public static SDFDoc __Create (long impl, Object ref)

#### public long __GetHandle ()

#### public Object __GetRefHandle ()

#### public void __SetRef (Object ref)

#### public boolean canSaveToPath (String path, SDFDoc.SaveMode saveMode)

Checks if a path is valid for a planned save operation

##### Returns

- - true if a path has sufficient file permissions to complete the save

##### Throws

PDFNetException |

#### public boolean canSaveToPath (String path, long flags)

This method is deprecated.
use `canSaveToPath(String, SaveMode)` instead. Checks if a path is valid for a planned save operation

##### Returns

- - true if a path has sufficient file permissions to complete the save

##### Throws

PDFNetException |

#### public void clearMarks ()

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

##### Throws

PDFNetException |

#### public void close ()

Close SDFDoc and release resources Frees the native memory of the object. This can be explicity called to control the deallocation of native memory and avoid situations where the garbage collector does not free the object in a timely manner.

##### Throws

PDFNetException |

#### public Obj createIndirectArray ()

Create an indirect array.

##### Returns

- the created indirect array as Obj

##### Throws

PDFNetException |

#### public Obj createIndirectBool (boolean value)

Create an indirect boolean

##### Parameters

value | of the indirect boolean object

##### Returns

- the created indirect boolean as Obj

##### Throws

PDFNetException |

#### public Obj createIndirectDict ()

Create an indirect dictionary

##### Returns

- the created indirect dictionary as Obj

##### Throws

PDFNetException |

#### public Obj createIndirectName (String name)

The following list of methods is used to create SDF/Cos indirect objects. Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects they can be shared).

##### Parameters

name | the name

##### Returns

- the obj

##### Throws

PDFNetException |

#### public Obj createIndirectNull ()

Create an indirect null

##### Returns

- the creatd indirect null as Obj

##### Throws

PDFNetException |

#### public Obj createIndirectNumber (double value)

Create an indirect number.

##### Parameters

value | of the indirect number

##### Returns

- the created indirect number

##### Throws

PDFNetException |

#### public Obj createIndirectStream (byte[] data)

Create an indirect stream from buffer

##### Parameters

data | input buffer

##### Returns

- the created indirect stream as Obj

##### Throws

PDFNetException |

#### public Obj createIndirectStream (FilterReader data)

Create an indirect stream from FilterReader

##### Parameters

data | input FilterReader

##### Returns

- the created indirect stream as Obj

##### Throws

PDFNetException |

#### public Obj createIndirectStream (byte[] data, Filter filter_chain)

Create an indirect stream

##### Parameters

data | input buffer
filter_chain | chain of filters

##### Returns

- the created indirect stream as Obj

##### Throws

PDFNetException |

#### public Obj createIndirectStream (FilterReader data, Filter filter_chain)

Create an indirect stream from FilterReader

##### Parameters

data | input FilterReader
filter_chain | chain of filters

##### Returns

- the created indirect stream as Obj

##### Throws

PDFNetException |

#### public Obj createIndirectString (byte[] value)

Create an indirect string.

##### Parameters

value | of indirect string

##### Returns

- the create indirect string as Obj

##### Throws

PDFNetException |

#### public Obj createIndirectString (String str)

Create an indirect string.

##### Parameters

str | value of indirect string

##### Returns

- the created indirect string as Obj

##### Throws

PDFNetException |

#### public void enableDiskCaching (boolean use_cache)

Enable or disable disk caching feature

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

use_cache | If true, this PDFDoc will use a temporary file to cache new content streams (this is the default behavior).

#### public String getFileName ()

Get SDFDoc filename

##### Returns

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

##### Throws

PDFNetException |

#### public String getHeader ()

Get the file header.

##### Returns

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

##### Throws

PDFNetException |

#### public Obj getHintStream ()

Get document's initial linearization hint stream if it is available.

##### Returns

- - the linearization hint stream of the original document or NULL if the hint stream is not available.

##### Throws

PDFNetException |

#### public Obj getLinearizationDict ()

Get document's initial linearization dictionary if it is available.

##### Returns

- - the linearization dictionary of the original document or NULL if the dictionary is not available.

##### Throws

PDFNetException |

#### public Obj getObj (long obj_num)

Get the Obj with specified object number

##### Parameters

obj_num | object number of the object to retrieve.

##### Returns

- - the latest version of the object matching specified object number.

##### Throws

PDFNetException |

#### public SecurityHandler getSecurityHandler ()

Get the security handler.

Note: InitSecurityHandler() should be called before GetSecurityHandler() in order to initialize the handler.

Returned security handler can be modified in order to change the security settings of the exisitng document. Changes to the current handler will not invalidate the access to the original file and will take effect during document Save().

If the security handler is modified, document will perform a full save even if `INCREMENTAL` was given in Save() method.

##### Returns

- Currently selected SecurityHandler.

#### public Obj getTrailer ()

Get root of the document as Obj

##### Returns

- - A dictionary representing the root of the document (i.e. a document trailer dictionary)

##### Throws

PDFNetException |

#### public boolean 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. Note: If this function returns true, it is not possible to incrementally save the document (see http://www.pdftron.com/kb_corrupt_xref)

##### Returns

- - true if document was found to be corrupted, and was repaired, during opening and has not been saved since.

##### Throws

PDFNetException |

#### public Obj importObj (Obj obj, boolean deep_copy)

Import obj to SDFDoc

Note: 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 responibility to delete free objects.

##### Parameters

obj | - an object to import.
deep_copy | - a boolean indicating whether to perform a deep or shallow copy. In case of shallow copy all indirect references will be set to null.

##### Returns

- - a pointer to the root indirect object in this document

##### Throws

PDFNetException |

#### public Obj[] importObjs (Obj[] obj_list, Obj[] exclusion_list)

The function performs a deep copy of all objects specified in the 'obj_list'. If objects in the list are directly or indirectly reffering 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.

- The function does not perform the shallow copy since ImportObj() can be used instead.

##### Parameters

obj_list | the obj_list
exclusion_list | a list of objects to not include in the deep copy

##### Returns

- - a list of imported root objects in this document

##### Throws

PDFNetException |

#### public Obj[] importObjs (Obj[] obj_list)

The function performs a deep copy of all objects specified in the 'obj_list'. If objects in the list are directly or indirectly reffering 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.

- The function does not perform the shallow copy since ImportObj() can be used instead.

##### Parameters

obj_list | the obj_list

##### Returns

- - a list of imported root objects in this document

##### Throws

PDFNetException |

#### public boolean initSecurityHandler (Object 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.

If the security handler was successfully initialized it can be later obtained using GetSecurityHandler() method.

Note: 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.

##### Parameters

custom_data | used to specify custom data that should be passed in SecurityHandler.initialize() callback.

##### Returns

- true if the given password successfully unlocked the document, false otherwise.

##### Throws

PDFNetException |

#### public boolean 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

- true if the SecurityHandler was successfully initialized (this may include authentication data collection, verification etc.), false otherwise.

##### Throws

PDFNetException |

#### public boolean initStdSecurityHandler (byte[] passwordBuffer)

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

passwordBuffer | 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

- true if the given password successfully unlocked the document, false otherwise.

##### Throws

PDFNetException |

#### public boolean initStdSecurityHandler (String 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

password | 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

- true if the given password successfully unlocked the document, false otherwise.

##### Throws

PDFNetException |

#### public boolean isEncrypted ()

Checks if SDFDoc is encrypted.

##### Returns

- true if the document is/was originally encrypted false otherwise.

##### Throws

PDFNetException |

#### public boolean isFullSaveRequired ()

Checks if is full save required.

##### Returns

- - true if the document requires full save.

##### Throws

PDFNetException |

#### public boolean isLinearized ()

Call this function to determine whether the document is represented in linearized (fast web view) format.

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 `INCREMENTAL` in the Save() method.

##### Returns

- - true if document is stored in fast web view format, false otherwise.

##### Throws

PDFNetException |

#### public boolean isModified ()

Checks if SDFDoc is modified.

##### Returns

- - true if document was modified, false otherwise

##### Throws

PDFNetException |

#### public void lock ()

Locks the document to prevent competing threads from accessiong 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().

##### Throws

PDFNetException |

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

##### Throws

PDFNetException |

#### public void removeSecurity ()

Removes all security from SDFDoc.

#### public void save (String path, SDFDoc.SaveMode saveMode, ProgressMonitor progress, String header)

Saves the document to a file. If a full save is requested to the original path, the file is saved to a file system-determined temporary file, the old file is deleted, and the temporary file is renamed to path. A full save with remove unused or linearization option may re-arrange object in the cross reference table. Therefore all pointers and references to document objects and resources should be re acquired in order to continue document editing. In order to use incremental save the specified path must match original path and `INCREMENTAL` should be given.

Note: - Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

Note: - If the original pdf has a corrupt xref table (see HasRepairedXref or http://www.pdftron.com/kb_corrupt_xref), then it can not be saved using the `INCREMENTAL`.

##### Parameters

path | - The full path name to which the file is saved.
saveMode | save mode (See `SDFDoc.SaveMode`).
progress | - A pointer to the progress interface. NULL if progress tracking is not required.
header | - File header. A new file header is set only during full save.

##### Throws

PDFNetException |

#### public void save (OutputStream stream, SDFDoc.SaveMode saveMode, ProgressMonitor progress, String header, int size)

Save SDFDoc to output stream

- Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

##### Parameters

stream | the output stream to save SDFDoc to
saveMode | save mode (See `SDFDoc.SaveMode`).
progress | A pointer to the progress interface. NULL if progress tracking is not required.
header | File header. A new file header is set only during full save.
size | size of the document in bytes

##### Throws

| PDFNetException
IOException | Signals that an I/O exception has occurred.
PDFNetException |

#### public void save (OutputStream stream, long flags, ProgressMonitor progress, String header, int size)

This method is deprecated.
use `save(OutputStream, SaveMode, ProgressMonitor, String, int)` instead. Save SDFDoc to output stream

- Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

##### Parameters

stream | the output stream to save SDFDoc to
flags | - A bit field composed of an OR of the following values: `e_incremental` `e_remove_unused` `e_hex_strings` `e_omit_xref` `e_linearized` `e_compatibility`
progress | A pointer to the progress interface. NULL if progress tracking is not required.
header | File header. A new file header is set only during full save.
size | size of the document in bytes

##### Throws

| PDFNetException
IOException | Signals that an I/O exception has occurred.
PDFNetException |

#### public byte[] save (long flags, ProgressMonitor progress, String header)

This method is deprecated.
use `save(SaveMode, ProgressMonitor, String)` instead. Saves the document to a memory buffer.

- Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

##### Parameters

flags | - A bit field composed of an OR of the following values: `e_incremental` `e_remove_unused` `e_hex_strings` `e_omit_xref` `e_linearized` `e_compatibility`
progress | - A pointer to the progress interface. NULL if progress tracking is not required.
header | - File header. A new file header is set only during full save.

##### Returns

- the byte[]

##### Throws

PDFNetException |

#### public void save (String path, long flags, ProgressMonitor progress, String header)

This method is deprecated.
use `save(String, SaveMode, ProgressMonitor, String)` instead. Saves the document to a file. If a full save is requested to the original path, the file is saved to a file system-determined temporary file, the old file is deleted, and the temporary file is renamed to path. A full save with remove unused or linearization option may re-arrange object in the cross reference table. Therefore all pointers and references to document objects and resources should be re acquired in order to continue document editing. In order to use incremental save the specified path must match original path and e_incremental flag bit should be set.

Note: - Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

Note: - If the original pdf has a corrupt xref table (see HasRepairedXref or http://www.pdftron.com/kb_corrupt_xref), then it can not be saved using the e_incremental flag.

##### Parameters

path | - The full path name to which the file is saved.
flags | - A bit field composed of an OR of the following values: `e_incremental` `e_remove_unused` `e_hex_strings` `e_omit_xref` `e_linearized` `e_compatibility`
progress | - A pointer to the progress interface. NULL if progress tracking is not required.
header | - File header. A new file header is set only during full save.

##### Throws

PDFNetException |

#### public byte[] save (SDFDoc.SaveMode saveMode, ProgressMonitor progress, String header)

Saves the document to a memory buffer.

- Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

##### Parameters

saveMode | save mode (See `SDFDoc.SaveMode`).
progress | - A pointer to the progress interface. NULL if progress tracking is not required.
header | - File header. A new file header is set only during full save.

##### Returns

- the byte[]

##### Throws

PDFNetException |

#### public void save (OutputStream stream, long flags, ProgressMonitor progress, String header)

This method is deprecated.
use `save(OutputStream, SaveMode, ProgressMonitor, String)` instead. Save SDFDoc to output stream

- Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

##### Parameters

stream | the output stream to save SDFDoc to
flags | - A bit field composed of an OR of the following values: `e_incremental` `e_remove_unused` `e_hex_strings` `e_omit_xref` `e_linearized` `e_compatibility`
progress | A pointer to the progress interface. NULL if progress tracking is not required.
header | File header. A new file header is set only during full save.

##### Throws

| PDFNetException
IOException | Signals that an I/O exception has occurred.
PDFNetException |

#### public void save (OutputStream stream, SDFDoc.SaveMode saveMode, ProgressMonitor progress, String header)

Save SDFDoc to output stream

- Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.

##### Parameters

stream | the output stream to save SDFDoc to
saveMode | save mode (See `SDFDoc.SaveMode`).
progress | A pointer to the progress interface. NULL if progress tracking is not required.
header | File header. A new file header is set only during full save.

##### Throws

| PDFNetException
IOException | Signals that an I/O exception has occurred.
PDFNetException |

#### public void setSecurityHandler (SecurityHandler handler)

The function sets a new SecurityHandler as the current security handler.

##### Parameters

handler | the new security handler * 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 `INCREMENTAL` was given in Save() method.

#### public void swap (long obj_num1, long 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

obj_num1 | the obj_num1
obj_num2 | the obj_num2

##### Throws

PDFNetException |

#### public boolean timedLock (int milliseconds)

Try locking the document, waiting no longer than specified number of milliseconds.

##### Parameters

milliseconds | the milliseconds

##### Returns

- true if the document is locked for multi-threaded access, false otherwise.

##### Throws

PDFNetException |

#### public boolean timedLockRead (int milliseconds)

Tries to obtain a read lock the document for <milliseconds> duration, and returns true if the lock was successfully acquired

##### Parameters

milliseconds | maximum time to wait

##### Returns

- true if the document is locked for multi-threaded access, false otherwise.

##### Throws

PDFNetException |

#### public boolean tryLockRead ()

Try obtaining a read lock on the document in non-blocking manner.

##### Returns

- true if the document is locked for multi-threaded access, false otherwise.

##### Throws

PDFNetException |

#### public void unlock ()

Removes the lock from the document.

##### Throws

PDFNetException |

#### public void unlockRead ()

Removes the read lock from the document.

##### Throws

PDFNetException |

#### public long xRefSize ()

Get size of the cross reference table

##### Returns

- size of cross reference table

##### Throws

PDFNetException |