Public Member Functions

PoDoFo::PdfMemDocument Class Reference

#include <PdfMemDocument.h>

Inheritance diagram for PoDoFo::PdfMemDocument:
PoDoFo::PdfDocument

List of all members.

Public Member Functions

 PdfMemDocument ()
 PdfMemDocument (const char *pszFilename)
virtual ~PdfMemDocument ()
void Load (const char *pszFilename)
void Load (const char *pBuffer, long lLen)
void Load (const PdfRefCountedInputDevice &rDevice)
void Write (const char *pszFilename)
void Write (PdfOutputDevice *pDevice)
void SetWriteMode (EPdfWriteMode eWriteMode)
virtual EPdfWriteMode GetWriteMode () const
void SetPdfVersion (EPdfVersion eVersion)
EPdfVersion GetPdfVersion () const
void SetPassword (const std::string &sPassword)
void SetEncrypted (const std::string &userPassword, const std::string &ownerPassword, int protection=PdfEncrypt::ePdfPermissions_Print|PdfEncrypt::ePdfPermissions_Edit|PdfEncrypt::ePdfPermissions_Copy|PdfEncrypt::ePdfPermissions_EditNotes|PdfEncrypt::ePdfPermissions_FillAndSign|PdfEncrypt::ePdfPermissions_Accessible|PdfEncrypt::ePdfPermissions_DocAssembly|PdfEncrypt::ePdfPermissions_HighPrint, PdfEncrypt::EPdfEncryptAlgorithm eAlgorithm=PdfEncrypt::ePdfEncryptAlgorithm_RC4V1, PdfEncrypt::EPdfKeyLength eKeyLength=PdfEncrypt::ePdfKeyLength_40)
void SetEncrypted (const PdfEncrypt &pEncrypt)
bool GetEncrypted () const
bool IsLinearized () const
const PdfVecObjectsGetObjects () const
PdfVecObjectsGetObjects ()
PdfObjectGetCatalog ()
const PdfObjectGetCatalog () const
const PdfObjectGetTrailer () const
PdfObjectGetStructTreeRoot () const
PdfObjectGetMetadata () const
PdfObjectGetMarkInfo () const
PdfFontGetFont (PdfObject *pObject)
const PdfMemDocumentInsertPages (const PdfMemDocument &rDoc, int inFirstPage, int inNumPages)
void DeletePages (int inFirstPage, int inNumPages)
virtual bool IsPrintAllowed () const
virtual bool IsEditAllowed () const
virtual bool IsCopyAllowed () const
virtual bool IsEditNotesAllowed () const
virtual bool IsFillAndSignAllowed () const
virtual bool IsAccessibilityAllowed () const
virtual bool IsDocAssemblyAllowed () const
virtual bool IsHighPrintAllowed () const
void FreeObjectMemory (const PdfReference &rRef, bool bForce=false)
void FreeObjectMemory (PdfObject *pObj, bool bForce=false)
const PdfEncryptGetEncrypt () const

Detailed Description

PdfMemDocument is the core class for reading and manipulating PDF files and writing them back to disk.

PdfMemDocument was designed to allow easy access to the object structur of a PDF file.

PdfMemDocument should be used whenever you want to change the object structure of a PDF file.

When you are only creating PDF files, please use PdfStreamedDocument which is usually faster for creating PDFs.

See also:
PdfDocument
PdfStreamedDocument
PdfParser
PdfWriter

Constructor & Destructor Documentation

PoDoFo::PdfMemDocument::PdfMemDocument (  ) 

Construct a new (empty) PdfMemDocument

PoDoFo::PdfMemDocument::PdfMemDocument ( const char *  pszFilename  ) 

Construct a PdfMemDocument from an existing PDF (on disk)

Parameters:
pszFilename filename of the file which is going to be parsed/opened

This might throw a PdfError( ePdfError_InvalidPassword ) exception if a password is required to read this PDF. Call SetPassword with the correct password in this case.

See also:
SetPassword
PoDoFo::PdfMemDocument::~PdfMemDocument (  )  [virtual]

Close down/destruct the PdfMemDocument


Member Function Documentation

void PoDoFo::PdfMemDocument::DeletePages ( int  inFirstPage,
int  inNumPages 
)

Deletes one or more pages from this document It does NOT remove any PdfObjects from memory - just the reference from the pages tree. If you want to delete resources of this page, you have to delete them yourself, but the resources might be used by other pages, too.

Parameters:
inFirstPage the first page number to delete (0-based)
inNumPages the number of pages to delete
Returns:
this document
void PoDoFo::PdfMemDocument::FreeObjectMemory ( const PdfReference rRef,
bool  bForce = false 
)

Tries to free all memory allocated by the given PdfObject (variables and streams) and reads it from disk again if it is requested another time.

This will only work if load on demand is used. Other- wise any call to this method will be ignored. Load on demand is currently always enabled when using PdfMemDocument. If the object is dirty if will not be free'd.

Parameters:
rRef free all memory allocated by the object with this reference.
bForce if true the object will be free'd even if IsDirty() returns true. So you will loose any changes made to this object.

This is an overloaded member for your convinience.

void PoDoFo::PdfMemDocument::FreeObjectMemory ( PdfObject pObj,
bool  bForce = false 
)

Tries to free all memory allocated by the given PdfObject (variables and streams) and reads it from disk again if it is requested another time.

This will only work if load on demand is used. Other- wise any call to this method will be ignored. Load on demand is currently always enabled when using PdfMemDocument. If the object is dirty if will not be free'd.

Parameters:
pObj free object from memory
bForce if true the object will be free'd even if IsDirty() returns true. So you will loose any changes made to this object.
See also:
IsDirty
const PdfObject* PoDoFo::PdfMemDocument::GetCatalog (  )  const [inline]

Get access to the internal Catalog dictionary or root object.

Returns:
PdfObject the documents catalog or NULL if no catalog is available

Reimplemented from PoDoFo::PdfDocument.

PdfObject* PoDoFo::PdfMemDocument::GetCatalog (  )  [inline]

Get access to the internal Catalog dictionary or root object.

Returns:
PdfObject the documents catalog or NULL if no catalog is available

Reimplemented from PoDoFo::PdfDocument.

const PdfEncrypt * PoDoFo::PdfMemDocument::GetEncrypt (  )  const [inline]
Returns:
the parsers encryption object or NULL if the read PDF file was not encrypted
bool PoDoFo::PdfMemDocument::GetEncrypted (  )  const [inline]
Returns:
true if this PdfMemDocument creates an encrypted PDF file
PdfFont * PoDoFo::PdfMemDocument::GetFont ( PdfObject pObject  ) 

Creates a PdfFont object from an existing font.

Parameters:
pObject a PdfObject that is a font
Returns:
PdfFont* a pointer to a new PdfFont object. The returned object is owned by the PdfDocument.
PdfObject* PoDoFo::PdfMemDocument::GetMarkInfo (  )  const [inline]

Get access to the MarkInfo dictionary (ISO 32000-1:2008 14.7.1)

Returns:
PdfObject the MarkInfo dictionary
PdfObject* PoDoFo::PdfMemDocument::GetMetadata (  )  const [inline]

Get access to the Metadata stream

Returns:
PdfObject the Metadata stream (should be in XML, using XMP grammar)
PdfVecObjects& PoDoFo::PdfMemDocument::GetObjects (  )  [inline]

Get a reference to the sorted internal objects vector. This is an overloaded function for your convinience.

Returns:
the internal objects vector.

Reimplemented from PoDoFo::PdfDocument.

const PdfVecObjects& PoDoFo::PdfMemDocument::GetObjects (  )  const [inline]

Get a reference to the sorted internal objects vector.

Returns:
the internal objects vector.

Reimplemented from PoDoFo::PdfDocument.

EPdfVersion PoDoFo::PdfMemDocument::GetPdfVersion (  )  const [inline, virtual]

Get the PDF version of the document

Returns:
EPdfVersion version of the pdf document

Implements PoDoFo::PdfDocument.

PdfObject* PoDoFo::PdfMemDocument::GetStructTreeRoot (  )  const [inline]

Get access to the StructTreeRoot dictionary

Returns:
PdfObject the StructTreeRoot dictionary
const PdfObject* PoDoFo::PdfMemDocument::GetTrailer (  )  const [inline]

Get the trailer dictionary which can be written unmodified to a pdf file.

Reimplemented from PoDoFo::PdfDocument.

virtual EPdfWriteMode PoDoFo::PdfMemDocument::GetWriteMode (  )  const [inline, virtual]

Get the write mode used for wirting the PDF

Returns:
the write mode

Implements PoDoFo::PdfDocument.

const PdfMemDocument & PoDoFo::PdfMemDocument::InsertPages ( const PdfMemDocument rDoc,
int  inFirstPage,
int  inNumPages 
)

Copies one or more pages from another PdfMemDocument to this document

Parameters:
rDoc the document to append
inFirstPage the first page number to copy (0-based)
inNumPages the number of pages to copy
Returns:
this document
bool PoDoFo::PdfMemDocument::IsAccessibilityAllowed (  )  const [inline, virtual]

Checks if it is allowed to extract text and graphics to support users with disabillities Every PDF consuming applications has to adhere this value!

Returns:
true if you are allowed to extract text and graphics to support users with disabillities
See also:
PdfEncrypt to set own document permissions.

Implements PoDoFo::PdfDocument.

bool PoDoFo::PdfMemDocument::IsCopyAllowed (  )  const [inline, virtual]

Checks if text and graphics extraction is allowed. Every PDF consuming applications has to adhere this value!

Returns:
true if you are allowed to extract text and graphics from this document
See also:
PdfEncrypt to set own document permissions.

Implements PoDoFo::PdfDocument.

bool PoDoFo::PdfMemDocument::IsDocAssemblyAllowed (  )  const [inline, virtual]

Checks if it is allowed to insert, create, rotate, delete pages or add bookmarks Every PDF consuming applications has to adhere this value!

Returns:
true if you are allowed to insert, create, rotate, delete pages or add bookmarks
See also:
PdfEncrypt to set own document permissions.

Implements PoDoFo::PdfDocument.

bool PoDoFo::PdfMemDocument::IsEditAllowed (  )  const [inline, virtual]

Checks if modifiying this document (besides annotations, form fields or changing pages) is allowed. Every PDF consuming applications has to adhere this value!

Returns:
true if you are allowed to modfiy this document
See also:
PdfEncrypt to set own document permissions.

Implements PoDoFo::PdfDocument.

bool PoDoFo::PdfMemDocument::IsEditNotesAllowed (  )  const [inline, virtual]

Checks if it is allowed to add or modify annotations or form fields Every PDF consuming applications has to adhere this value!

Returns:
true if you are allowed to add or modify annotations or form fields
See also:
PdfEncrypt to set own document permissions.

Implements PoDoFo::PdfDocument.

bool PoDoFo::PdfMemDocument::IsFillAndSignAllowed (  )  const [inline, virtual]

Checks if it is allowed to fill in existing form or signature fields Every PDF consuming applications has to adhere this value!

Returns:
true if you are allowed to fill in existing form or signature fields
See also:
PdfEncrypt to set own document permissions.

Implements PoDoFo::PdfDocument.

bool PoDoFo::PdfMemDocument::IsHighPrintAllowed (  )  const [inline, virtual]

Checks if it is allowed to print a high quality version of this document Every PDF consuming applications has to adhere this value!

Returns:
true if you are allowed to print a high quality version of this document
See also:
PdfEncrypt to set own document permissions.

Implements PoDoFo::PdfDocument.

bool PoDoFo::PdfMemDocument::IsLinearized (  )  const [inline, virtual]

Returns wether this PDF document is linearized, aka weboptimized

Returns:
true if the PDF document is linearized

Implements PoDoFo::PdfDocument.

bool PoDoFo::PdfMemDocument::IsPrintAllowed (  )  const [inline, virtual]

Checks if printing this document is allowed. Every PDF consuming applications has to adhere this value!

Returns:
true if you are allowed to print this document
See also:
PdfEncrypt to set own document permissions.

Implements PoDoFo::PdfDocument.

void PoDoFo::PdfMemDocument::Load ( const char *  pBuffer,
long  lLen 
)

Load a PdfMemDocument from a buffer in memory

Parameters:
pBuffer a memory area containing the PDF data
lLen length of the buffer

This might throw a PdfError( ePdfError_InvalidPassword ) exception if a password is required to read this PDF. Call SetPassword with the correct password in this case.

See also:
SetPassword
void PoDoFo::PdfMemDocument::Load ( const PdfRefCountedInputDevice rDevice  ) 

Load a PdfMemDocument from a PdfRefCountedInputDevice

Parameters:
rDevice the input device containing the PDF

This might throw a PdfError( ePdfError_InvalidPassword ) exception if a password is required to read this PDF. Call SetPassword with the correct password in this case.

See also:
SetPassword
void PoDoFo::PdfMemDocument::Load ( const char *  pszFilename  ) 

Load a PdfMemDocument from a file

Parameters:
pszFilename filename of the file which is going to be parsed/opened

This might throw a PdfError( ePdfError_InvalidPassword ) exception if a password is required to read this PDF. Call SetPassword with the correct password in this case.

See also:
SetPassword
void PoDoFo::PdfMemDocument::SetEncrypted ( const PdfEncrypt pEncrypt  ) 

Encrypt the document during writing using a PdfEncrypt object

Parameters:
pEncrypt an encryption object that will be owned by PdfMemDocument
void PoDoFo::PdfMemDocument::SetEncrypted ( const std::string &  userPassword,
const std::string &  ownerPassword,
int  protection = PdfEncrypt::ePdfPermissions_Print | PdfEncrypt::ePdfPermissions_Edit | PdfEncrypt::ePdfPermissions_Copy | PdfEncrypt::ePdfPermissions_EditNotes | PdfEncrypt::ePdfPermissions_FillAndSign | PdfEncrypt::ePdfPermissions_Accessible | PdfEncrypt::ePdfPermissions_DocAssembly | PdfEncrypt::ePdfPermissions_HighPrint,
PdfEncrypt::EPdfEncryptAlgorithm  eAlgorithm = PdfEncrypt::ePdfEncryptAlgorithm_RC4V1,
PdfEncrypt::EPdfKeyLength  eKeyLength = PdfEncrypt::ePdfKeyLength_40 
)

Encrypt the document during writing.

Parameters:
userPassword the user password (if empty the user does not have to enter a password to open the document)
ownerPassword the owner password
protection several EPdfPermissions values or'ed together to set the users permissions for this document
eAlgorithm the revision of the encryption algorithm to be used
eKeyLength the length of the encryption key ranging from 40 to 128 bits (only used if eAlgorithm == ePdfEncryptAlgorithm_RC4V2)
See also:
PdfEncrypt
void PoDoFo::PdfMemDocument::SetPassword ( const std::string &  sPassword  ) 

If you try to open an encrypted PDF file, which requires a password to open, PoDoFo will throw a PdfError( ePdfError_InvalidPassword ) exception.

If you got such an exception, you have to set a password which should be used for opening the PDF.

The usual way will be to ask the user for the password and set the password using this method.

PdfParser will immediately continue to read the PDF file.

Parameters:
sPassword a user or owner password which can be used to open an encrypted PDF file If the password is invalid, a PdfError( ePdfError_InvalidPassword ) exception is thrown!
void PoDoFo::PdfMemDocument::SetPdfVersion ( EPdfVersion  eVersion  )  [inline]

Set the PDF Version of the document. Has to be called before Write() to have an effect.

Parameters:
eVersion version of the pdf document
void PoDoFo::PdfMemDocument::SetWriteMode ( EPdfWriteMode  eWriteMode  )  [inline]

Set the write mode to use when writing the PDF.

Parameters:
eWriteMode write mode
void PoDoFo::PdfMemDocument::Write ( const char *  pszFilename  ) 

Writes the complete document to a file

Parameters:
pszFilename filename of the document
See also:
Write

This is an overloaded member function for your convinience.

TODO: We will get problems here on linux, if we write to the same filename we read the document from. Because the PdfParserObjects will read there streams data from the file while we are writing it. The problem is that the stream data won't exist at this time as we truncated the file already to zero length by opening it writeable.

void PoDoFo::PdfMemDocument::Write ( PdfOutputDevice pDevice  ) 

Writes the complete document to an output device

Parameters:
pDevice write to this output device

TODO: We will get problems here on linux, if we write to the same filename we read the document from. Because the PdfParserObjects will read there streams data from the file while we are writing it. The problem is that the stream data won't exist at this time as we truncated the file already to zero length by opening it writeable.