pdftron::SDF::SDFDoc Class Reference

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

#include <SDFDoc.h>

List of all members.

Public Types

enum  SaveOptions {
  e_incremental = 0x01, e_remove_unused = 0x02, e_hex_strings = 0x04, e_omit_xref = 0x08,
  e_linearized = 0x10
}

Public Member Functions

 SDFDoc ()
 Default constructor.
 SDFDoc (const UString &filepath)
 Open a SDF/Cos document from a file.
 SDFDoc (const char *filepath)
 SDFDoc (Filters::Filter stream)
 Open a SDF/Cos document from a Filter (i.e.
 SDFDoc (const char *buf, size_t buf_size)
 Open a SDF/Cos document from a memory buffer.
 ~SDFDoc ()
 Destructor.
bool IsEncrypted ()
bool InitSecurityHandler (void *custom_data=0)
 Initializes document's SecurityHandler.
bool InitStdSecurityHandler (const char *password, int password_sz=0)
 Initializes document's SecurityHandler using the supplied password.
bool IsModified () const
bool IsFullSaveRequired () const
Obj GetTrailer ()
Obj GetObj (const UInt32 obj_num) const
Obj ImportObj (Obj obj, bool deep_copy)
std::vector< ObjImportObjs (const std::vector< Obj > &obj_list)
 The function performs a deep copy of all objects specified in the 'obj_list'.
UInt32 XRefSize () const
void ClearMarks ()
 Removes 'marked' flag from all objects in cross reference table.
void Save (const UString &path, UInt32 flags, Common::ProgressMonitor *progress, const char *header)
 Saves the document to a file.
void Save (const char *&out_buf, size_t &out_buf_size, UInt32 flags, Common::ProgressMonitor *progress, const char *header)
 Saves the document to a memory buffer.
const char * GetHeader () const
SecurityHandler GetSecurityHandler ()
void SetSecurityHandler (SecurityHandler handler)
 The function sets a new SecurityHandler as the current security handler.
void RemoveSecurity ()
 This function removes document security.
void Swap (UInt32 obj_num1, UInt32 obj_num2)
 Sometimes it is desirable to modify all indirect references to a given indirect object.
Obj CreateIndirectName (const char *name)
 The following list of methods is used to create SDF/Cos indirect objects.
Obj CreateIndirectArray ()
Obj CreateIndirectBool (bool value)
Obj CreateIndirectDict ()
Obj CreateIndirectNull ()
Obj CreateIndirectNumber (double value)
Obj CreateIndirectString (const UChar *value, UInt32 size)
Obj CreateIndirectString (const UString &str)
Obj CreateIndirectStream (Filters::FilterReader &data, Filters::Filter filter_chain=Filters::Filter())
Obj CreateIndirectStream (const char *data, const size_t data_size, Filters::Filter filter_chain=Filters::Filter())
bool IsLinearized () const
 Call this function to determine whether the document is represented in linearized (fast web view) format.
SDF::Obj GetLinearizationDict () const
 Returns document's initial linearization dictionary if it is available.
SDF::Obj GetHintStream () const
 Returns document's initial linearization hint stream if it is available.
void Lock ()
 Locks the document to prevent competing threads from accessing the document at the same time.
void Unlock ()
 Removes the lock from the document.
bool IsLocked ()
bool TryLock (int milliseconds=0)
 Try locking the document, waiting no longer than specified number of milliseconds.
UString GetFileName () const
void EnableDiskCaching (bool 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).


Detailed Description

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.


Member Enumeration Documentation

Enumerator:
e_incremental 
e_remove_unused 
e_hex_strings 
e_omit_xref 
e_linearized 


Constructor & Destructor Documentation

pdftron::SDF::SDFDoc::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.

pdftron::SDF::SDFDoc::SDFDoc ( const UString filepath  ) 

Open a SDF/Cos document from a file.

Parameters:
filepath - path name to the file.
Note:
Make sure to call InitStdSecurityHandler() or InitSecurityHandler() after SDFDoc(...) in case the document is encrypted.

pdftron::SDF::SDFDoc::SDFDoc ( const char *  filepath  ) 

pdftron::SDF::SDFDoc::SDFDoc ( Filters::Filter  stream  ) 

Open a SDF/Cos document from a Filter (i.e.

a data stream) object.

Parameters:
stream - input stream containing a serialized document. The input stream may be a random-access file, memory buffer, slow HTTP connection etc.
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.

pdftron::SDF::SDFDoc::SDFDoc ( const char *  buf,
size_t  buf_size 
)

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.

Parameters:
buf - a memory buffer containing the serialized document
buf_size - the size of memory buffer.
Note:
Make sure to call InitStdSecurityHandler() or InitSecurityHandler() after SDFDoc(...) in case the document is encrypted.

pdftron::SDF::SDFDoc::~SDFDoc (  ) 

Destructor.


Member Function Documentation

bool pdftron::SDF::SDFDoc::IsEncrypted (  ) 

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

bool pdftron::SDF::SDFDoc::InitSecurityHandler ( void *  custom_data = 0  ) 

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.

Exceptions:
An exception is thrown if the matching handler for document's security was not found in the global SecurityManager. In this case, you need to register additional custom security handlers with the global SecurityManager (using SecurityManagerSingleton).
Returns:
true if the SecurityHandler was successfully initialized (this may include authentication data collection, verification etc.), false otherwise.
Parameters:
custom_data An optional parameter used to specify custom data that should be passed in SecurityHandler::Initialize() callback.

bool pdftron::SDF::SDFDoc::InitStdSecurityHandler ( const char *  password,
int  password_sz = 0 
)

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.

Returns:
true if the given password successfully unlocked the document, false otherwise.
Exceptions:
An exception is thrown if the document's security Filter is not 'Standard'. In this case, you need to register additional custom security handlers with the global SecurityManager (SecurityManagerSingleton).
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.
password_len 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.

bool pdftron::SDF::SDFDoc::IsModified (  )  const

Returns:
- true if document was modified, false otherwise

bool pdftron::SDF::SDFDoc::IsFullSaveRequired (  )  const

Returns:
- true if the document requires full save.

Obj pdftron::SDF::SDFDoc::GetTrailer (  ) 

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

Obj pdftron::SDF::SDFDoc::GetObj ( const UInt32  obj_num  )  const

Parameters:
- obj_num object number of the object to retrieve.
Returns:
- the latest version of the object matching specified object number.
Exceptions:
- exception is thrown if the object is not found.

Obj pdftron::SDF::SDFDoc::ImportObj ( Obj  obj,
bool  deep_copy 
)

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.
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 pointer to the root indirect object in this document

std::vector<Obj> pdftron::SDF::SDFDoc::ImportObjs ( const std::vector< 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 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.

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

Parameters:
obj - a list of root objects to import. All directly or indirectly objects will be imported as well.
Returns:
- a list of imported root objects in this document

UInt32 pdftron::SDF::SDFDoc::XRefSize (  )  const

Returns:
- The size of cross reference table

void pdftron::SDF::SDFDoc::ClearMarks (  ) 

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

void pdftron::SDF::SDFDoc::Save ( const UString path,
UInt32  flags,
Common::ProgressMonitor *  progress,
const char *  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 e_incremental flag bit should be set.

Parameters:
path - The full path name to which the file is saved.
flags - A bit field composed of an OR of the SDFDoc::SaveOptions values.
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.
Exceptions:
- if the file can't be opened for saving or if there is a problem during Save an Exception object will be thrown.

void pdftron::SDF::SDFDoc::Save ( const char *&  out_buf,
size_t &  out_buf_size,
UInt32  flags,
Common::ProgressMonitor *  progress,
const char *  header 
)

Saves the document to a memory buffer.

Parameters:
out_buf a pointer to the buffer containing the serialized version of the document. (C++ Note) The buffer is owned by a document and the client doesn't need to do any initialization or cleanup.
out_buf_size the size of the serialized document (i.e. out_buf) in bytes.
flags - A bit field composed of an OR of the SDFDoc::SaveOptions values. Note that this method ignores e_incremental flag.
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.
Exceptions:
- if there is a problem during Save an Exception object will be thrown.

const char* pdftron::SDF::SDFDoc::GetHeader (  )  const

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.

SecurityHandler pdftron::SDF::SDFDoc::GetSecurityHandler (  ) 

Returns:
Currently selected SecurityHandler.
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 existing 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 e_incremental was given as a flag in Save() method.

void pdftron::SDF::SDFDoc::SetSecurityHandler ( SecurityHandler  handler  ) 

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

Parameters:
- new SecurityHandler
Note:
Setting a new security 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 e_incremental was given as a flag in Save() method.

void pdftron::SDF::SDFDoc::RemoveSecurity (  ) 

This function removes document security.

void pdftron::SDF::SDFDoc::Swap ( UInt32  obj_num1,
UInt32  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 & obj_num2 are object numbers of objects to be swapped.
Exceptions:
the function throws exception in case the swap can't be performed.

Obj pdftron::SDF::SDFDoc::CreateIndirectName ( const char *  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).

Note:
In C++ doc.CreateIndirect???(...) is equivalent to ???CreateIndirect(...).

Obj pdftron::SDF::SDFDoc::CreateIndirectArray (  ) 

Obj pdftron::SDF::SDFDoc::CreateIndirectBool ( bool  value  ) 

Obj pdftron::SDF::SDFDoc::CreateIndirectDict (  ) 

Obj pdftron::SDF::SDFDoc::CreateIndirectNull (  ) 

Obj pdftron::SDF::SDFDoc::CreateIndirectNumber ( double  value  ) 

Obj pdftron::SDF::SDFDoc::CreateIndirectString ( const UChar value,
UInt32  size 
)

Obj pdftron::SDF::SDFDoc::CreateIndirectString ( const UString str  ) 

Obj pdftron::SDF::SDFDoc::CreateIndirectStream ( Filters::FilterReader data,
Filters::Filter  filter_chain = Filters::Filter() 
)

Note:
After calling the following methods the filter object is invalidated and should not be used

Obj pdftron::SDF::SDFDoc::CreateIndirectStream ( const char *  data,
const size_t  data_size,
Filters::Filter  filter_chain = Filters::Filter() 
)

bool pdftron::SDF::SDFDoc::IsLinearized (  )  const

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

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

SDF::Obj pdftron::SDF::SDFDoc::GetLinearizationDict (  )  const

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

SDF::Obj pdftron::SDF::SDFDoc::GetHintStream (  )  const

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

void pdftron::SDF::SDFDoc::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().

void pdftron::SDF::SDFDoc::Unlock (  ) 

Removes the lock from the document.

bool pdftron::SDF::SDFDoc::IsLocked (  ) 

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

bool pdftron::SDF::SDFDoc::TryLock ( int  milliseconds = 0  ) 

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

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

UString pdftron::SDF::SDFDoc::GetFileName (  )  const

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.

void pdftron::SDF::SDFDoc::EnableDiskCaching ( bool  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).

Use this function to enable to disable this feature dynamically.


© 2002-2010 PDFTron Systems Inc.