PoDoFo 0.9.6
Public Member Functions | List of all members
PoDoFo::PdfMemDocument Class Reference

#include <PdfMemDocument.h>

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

Public Member Functions

 PdfMemDocument ()
 
 PdfMemDocument (bool bOnlyTrailer)
 
 PdfMemDocument (const char *pszFilename, bool bForUpdate=false)
 
virtual ~PdfMemDocument ()
 
void Load (const char *pszFilename, bool bForUpdate=false)
 
void LoadFromBuffer (const char *pBuffer, long lLen, bool bForUpdate=false)
 
void LoadFromDevice (const PdfRefCountedInputDevice &rDevice, bool bForUpdate=false)
 
bool IsLoaded (void) const
 
void Write (const char *pszFilename)
 
void Write (PdfOutputDevice *pDevice)
 
void WriteUpdate (const char *pszFilename)
 
void WriteUpdate (PdfOutputDevice *pDevice, bool bTruncate=true)
 
void SetWriteMode (EPdfWriteMode eWriteMode)
 
virtual EPdfWriteMode GetWriteMode () const
 
void SetPdfVersion (EPdfVersion eVersion)
 
EPdfVersion GetPdfVersion () const
 
void AddPdfExtension (const char *ns, pdf_int64 level)
 
bool HasPdfExtension (const char *ns, pdf_int64 level) const
 
void RemovePdfExtension (const char *ns, pdf_int64 level)
 
std::vector< PdfExtensionGetPdfExtensions () 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_AESV2, 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
 
PdfObjectGetLanguage () 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
 
- Public Member Functions inherited from PoDoFo::PdfDocument
virtual ~PdfDocument ()
 
virtual EPdfWriteMode GetWriteMode () const =0
 
virtual EPdfVersion GetPdfVersion () const =0
 
virtual bool IsLinearized () const =0
 
PdfInfoGetInfo () const
 
PdfOutlinesGetOutlines (bool bCreate=ePdfCreateObject)
 
PdfNamesTree * GetNamesTree (bool bCreate=ePdfCreateObject)
 
PdfAcroForm * GetAcroForm (bool bCreate=ePdfCreateObject, EPdfAcroFormDefaulAppearance eDefaultAppearance=ePdfAcroFormDefaultAppearance_BlackText12pt)
 
PdfPagesTreeGetPagesTree () const
 
int GetPageCount () const
 
PdfPageGetPage (int nIndex) const
 
PdfFontCreateFont (const char *pszFontName, bool bSymbolCharset=false, const PdfEncoding *const pEncoding=PdfEncodingFactory::GlobalWinAnsiEncodingInstance(), PdfFontCache::EFontCreationFlags eFontCreationFlags=PdfFontCache::eFontCreationFlags_AutoSelectBase14, bool bEmbedd=true)
 
PdfFontCreateFont (const char *pszFontName, bool bBold, bool bItalic, bool bSymbolCharset=false, const PdfEncoding *const pEncoding=PdfEncodingFactory::GlobalWinAnsiEncodingInstance(), PdfFontCache::EFontCreationFlags eFontCreationFlags=PdfFontCache::eFontCreationFlags_AutoSelectBase14, bool bEmbedd=true, const char *pszFileName=NULL)
 
PdfFontCreateFont (FT_Face face, bool bSymbolCharset=false, const PdfEncoding *const pEncoding=PdfEncodingFactory::GlobalWinAnsiEncodingInstance(), bool bEmbedd=true)
 
PdfFontCreateDuplicateFontType1 (PdfFont *pFont, const char *pszSuffix)
 
PdfFontCreateFontSubset (const char *pszFontName, bool bBold, bool bItalic, bool bSymbolCharset=false, const PdfEncoding *const pEncoding=PdfEncodingFactory::GlobalWinAnsiEncodingInstance(), const char *pszFileName=NULL)
 
FT_Library GetFontLibrary () const
 
void EmbedSubsetFonts ()
 
PdfPageCreatePage (const PdfRect &rSize)
 
void CreatePages (const std::vector< PdfRect > &vecSizes)
 
PdfPageInsertPage (const PdfRect &rSize, int atIndex)
 
const PdfDocumentAppend (const PdfMemDocument &rDoc, bool bAppendAll=true)
 
const PdfDocumentInsertExistingPageAt (const PdfMemDocument &rDoc, int nPageIndex, int nAtIndex)
 
PdfRect FillXObjectFromDocumentPage (PdfXObject *pXObj, const PdfMemDocument &rDoc, int nPage, bool bUseTrimBox)
 
PdfRect FillXObjectFromExistingPage (PdfXObject *pXObj, int nPage, bool bUseTrimBox)
 
PdfRect FillXObjectFromPage (PdfXObject *pXObj, const PdfPage *pPage, bool bUseTrimBox, unsigned int difference)
 
void AttachFile (const PdfFileSpec &rFileSpec)
 
PdfFileSpecGetAttachment (const PdfString &rName)
 
void AddNamedDestination (const PdfDestination &rDest, const PdfString &rsName)
 
void SetPageMode (EPdfPageMode inMode)
 
EPdfPageMode GetPageMode (void) const
 
void SetUseFullScreen (void)
 
void SetPageLayout (EPdfPageLayout inLayout)
 
void SetHideToolbar (void)
 
void SetHideMenubar (void)
 
void SetHideWindowUI (void)
 
void SetFitWindow (void)
 
void SetCenterWindow (void)
 
void SetDisplayDocTitle (void)
 
void SetPrintScaling (PdfName &inScalingType)
 
void SetBaseURI (const std::string &inBaseURI)
 
void SetLanguage (const std::string &inLanguage)
 
void SetBindingDirection (PdfName &inDirection)
 
virtual bool IsPrintAllowed () const =0
 
virtual bool IsEditAllowed () const =0
 
virtual bool IsCopyAllowed () const =0
 
virtual bool IsEditNotesAllowed () const =0
 
virtual bool IsFillAndSignAllowed () const =0
 
virtual bool IsAccessibilityAllowed () const =0
 
virtual bool IsDocAssemblyAllowed () const =0
 
virtual bool IsHighPrintAllowed () const =0
 
PdfVecObjectsGetObjects ()
 
const PdfVecObjectsGetObjects () const
 
void SetFontConfigWrapper (const PdfFontConfigWrapper &rFontConfig)
 

Additional Inherited Members

- Protected Member Functions inherited from PoDoFo::PdfDocument
 PdfDocument (bool bEmpty=false)
 
void SetInfo (PdfInfo *pInfo)
 
PdfObjectGetCatalog ()
 
const PdfObjectGetCatalog () const
 
void SetCatalog (PdfObject *pObject)
 
PdfObjectGetTrailer ()
 
const PdfObjectGetTrailer () const
 
void SetTrailer (PdfObject *pObject)
 
PdfObjectGetNamedObjectFromCatalog (const char *pszName) const
 
void InitPagesTree ()
 
void FixObjectReferences (PdfObject *pObject, int difference)
 
void SetViewerPreference (const PdfName &whichPref, const PdfObject &valueObj)
 
void SetViewerPreference (const PdfName &whichPref, bool inValue)
 
void Clear ()
 

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

◆ PdfMemDocument() [1/3]

PoDoFo::PdfMemDocument::PdfMemDocument ( )

Construct a new (empty) PdfMemDocument

◆ PdfMemDocument() [2/3]

PoDoFo::PdfMemDocument::PdfMemDocument ( bool  bOnlyTrailer)

Construct a new (empty) PdfMemDocument

◆ PdfMemDocument() [3/3]

PoDoFo::PdfMemDocument::PdfMemDocument ( const char *  pszFilename,
bool  bForUpdate = false 
)

Construct a PdfMemDocument from an existing PDF (on disk)

Parameters
pszFilenamefilename of the file which is going to be parsed/opened
bForUpdatewhether to load for incremental update

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.

When the bForUpdate is set to true, the pszFilename is copied for later use by WriteUpdate.

See also
SetPassword, WriteUpdate

◆ ~PdfMemDocument()

PoDoFo::PdfMemDocument::~PdfMemDocument ( )
virtual

Close down/destruct the PdfMemDocument

Member Function Documentation

◆ AddPdfExtension()

void PoDoFo::PdfMemDocument::AddPdfExtension ( const char *  ns,
pdf_int64  level 
)

Add a vendor-specific extension to the current PDF version.

Parameters
nsnamespace of the extension
levellevel of the extension

◆ DeletePages()

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
inFirstPagethe first page number to delete (0-based)
inNumPagesthe number of pages to delete
Returns
this document

◆ FreeObjectMemory() [1/2]

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
rReffree all memory allocated by the object with this reference.
bForceif 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.

◆ FreeObjectMemory() [2/2]

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
pObjfree object from memory
bForceif 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

◆ GetCatalog() [1/2]

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

◆ GetCatalog() [2/2]

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

◆ GetEncrypt()

const PdfEncrypt * PoDoFo::PdfMemDocument::GetEncrypt ( ) const
inline
Returns
the parsers encryption object or NULL if the read PDF file was not encrypted

◆ GetEncrypted()

bool PoDoFo::PdfMemDocument::GetEncrypted ( ) const
inline
Returns
true if this PdfMemDocument creates an encrypted PDF file

◆ GetFont()

PdfFont * PoDoFo::PdfMemDocument::GetFont ( PdfObject pObject)

Creates a PdfFont object from an existing font.

Parameters
pObjecta PdfObject that is a font
Returns
PdfFont* a pointer to a new PdfFont object. The returned object is owned by the PdfDocument.

◆ GetLanguage()

PdfObject * PoDoFo::PdfMemDocument::GetLanguage ( ) const
inline

Get access to the RFC 3066 natural language id for the document (ISO 32000-1:2008 14.9.2.1)

Returns
PdfObject the language ID string

◆ GetMarkInfo()

PdfObject * PoDoFo::PdfMemDocument::GetMarkInfo ( ) const
inline

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

Returns
PdfObject the MarkInfo dictionary

◆ GetMetadata()

PdfObject * PoDoFo::PdfMemDocument::GetMetadata ( ) const
inline

Get access to the Metadata stream

Returns
PdfObject the Metadata stream (should be in XML, using XMP grammar)

◆ GetObjects() [1/2]

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.

◆ GetObjects() [2/2]

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

Get a reference to the sorted internal objects vector.

Returns
the internal objects vector.

◆ GetPdfExtensions()

std::vector< PdfExtension > PoDoFo::PdfMemDocument::GetPdfExtensions ( ) const

Return the list of all vendor-specific extensions to the current PDF version.

Parameters
nsnamespace of the extension
levellevel of the extension

◆ GetPdfVersion()

EPdfVersion PoDoFo::PdfMemDocument::GetPdfVersion ( ) const
inlinevirtual

Get the PDF version of the document

Returns
EPdfVersion version of the pdf document

Implements PoDoFo::PdfDocument.

◆ GetStructTreeRoot()

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

Get access to the StructTreeRoot dictionary

Returns
PdfObject the StructTreeRoot dictionary

◆ GetTrailer()

const PdfObject * PoDoFo::PdfMemDocument::GetTrailer ( ) const
inline

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

◆ GetWriteMode()

virtual EPdfWriteMode PoDoFo::PdfMemDocument::GetWriteMode ( ) const
inlinevirtual

Get the write mode used for wirting the PDF

Returns
the write mode

Implements PoDoFo::PdfDocument.

◆ HasPdfExtension()

bool PoDoFo::PdfMemDocument::HasPdfExtension ( const char *  ns,
pdf_int64  level 
) const

Checks whether the documents is tagged to imlpement a vendor-specific extension to the current PDF version.

Parameters
nsnamespace of the extension
levellevel of the extension

◆ InsertPages()

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

Copies one or more pages from another PdfMemDocument to this document

Parameters
rDocthe document to append
inFirstPagethe first page number to copy (0-based)
inNumPagesthe number of pages to copy
Returns
this document

◆ IsAccessibilityAllowed()

bool PoDoFo::PdfMemDocument::IsAccessibilityAllowed ( ) const
inlinevirtual

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.

◆ IsCopyAllowed()

bool PoDoFo::PdfMemDocument::IsCopyAllowed ( ) const
inlinevirtual

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.

◆ IsDocAssemblyAllowed()

bool PoDoFo::PdfMemDocument::IsDocAssemblyAllowed ( ) const
inlinevirtual

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.

◆ IsEditAllowed()

bool PoDoFo::PdfMemDocument::IsEditAllowed ( ) const
inlinevirtual

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.

◆ IsEditNotesAllowed()

bool PoDoFo::PdfMemDocument::IsEditNotesAllowed ( ) const
inlinevirtual

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.

◆ IsFillAndSignAllowed()

bool PoDoFo::PdfMemDocument::IsFillAndSignAllowed ( ) const
inlinevirtual

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.

◆ IsHighPrintAllowed()

bool PoDoFo::PdfMemDocument::IsHighPrintAllowed ( ) const
inlinevirtual

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.

◆ IsLinearized()

bool PoDoFo::PdfMemDocument::IsLinearized ( ) const
inlinevirtual

Returns wether this PDF document is linearized, aka weboptimized

Returns
true if the PDF document is linearized

Implements PoDoFo::PdfDocument.

◆ IsLoaded()

bool PoDoFo::PdfMemDocument::IsLoaded ( void  ) const
inline

Returns whether the document is fully loaded.

◆ IsPrintAllowed()

bool PoDoFo::PdfMemDocument::IsPrintAllowed ( ) const
inlinevirtual

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.

◆ Load()

void PoDoFo::PdfMemDocument::Load ( const char *  pszFilename,
bool  bForUpdate = false 
)

Load a PdfMemDocument from a file

Parameters
pszFilenamefilename of the file which is going to be parsed/opened
bForUpdatewhether to load for incremental update

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.

When the bForUpdate is set to true, the pszFilename is copied for later use by WriteUpdate.

See also
SetPassword, WriteUpdate, LoadFromBuffer, LoadFromDevice

◆ LoadFromBuffer()

void PoDoFo::PdfMemDocument::LoadFromBuffer ( const char *  pBuffer,
long  lLen,
bool  bForUpdate = false 
)

Load a PdfMemDocument from a buffer in memory

Parameters
pBuffera memory area containing the PDF data
lLenlength of the buffer
bForUpdatewhether to load for incremental update

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.

When the bForUpdate is set to true, the memory buffer is copied for later use by WriteUpdate.

See also
SetPassword, WriteUpdate, Load, LoadFromDevice

◆ LoadFromDevice()

void PoDoFo::PdfMemDocument::LoadFromDevice ( const PdfRefCountedInputDevice rDevice,
bool  bForUpdate = false 
)

Load a PdfMemDocument from a PdfRefCountedInputDevice

Parameters
rDevicethe input device containing the PDF
bForUpdatewhether to load for incremental update

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.

When the bForUpdate is set to true, the rDevice is referenced for later use by WriteUpdate.

See also
SetPassword, WriteUpdate, Load, LoadFromBuffer

◆ RemovePdfExtension()

void PoDoFo::PdfMemDocument::RemovePdfExtension ( const char *  ns,
pdf_int64  level 
)

Remove a vendor-specific extension to the current PDF version.

Parameters
nsnamespace of the extension
levellevel of the extension

◆ SetEncrypted() [1/2]

void PoDoFo::PdfMemDocument::SetEncrypted ( const PdfEncrypt pEncrypt)

Encrypt the document during writing using a PdfEncrypt object

Parameters
pEncryptan encryption object that will be owned by PdfMemDocument

◆ SetEncrypted() [2/2]

Encrypt the document during writing.

Parameters
userPasswordthe user password (if empty the user does not have to enter a password to open the document)
ownerPasswordthe owner password
protectionseveral EPdfPermissions values or'ed together to set the users permissions for this document
eAlgorithmthe revision of the encryption algorithm to be used
eKeyLengththe length of the encryption key ranging from 40 to 256 bits (only used if eAlgorithm >= ePdfEncryptAlgorithm_RC4V2)
See also
PdfEncrypt

◆ SetPassword()

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
sPassworda 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!

◆ SetPdfVersion()

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
eVersionversion of the pdf document

◆ SetWriteMode()

void PoDoFo::PdfMemDocument::SetWriteMode ( EPdfWriteMode  eWriteMode)
inline

Set the write mode to use when writing the PDF.

Parameters
eWriteModewrite mode

◆ Write() [1/2]

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

Writes the complete document to a file

Parameters
pszFilenamefilename of the document
See also
Write, WriteUpdate

This is an overloaded member function for your convenience.

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.

◆ Write() [2/2]

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

Writes the complete document to an output device

Parameters
pDevicewrite to this output device
See also
WriteUpdate

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.

◆ WriteUpdate() [1/2]

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

Writes the document changes to a file

Parameters
pszFilenamefilename of the document

Writes the document changes to a file as an incremental update. The document should be loaded with bForUpdate = true, otherwise an exception is thrown.

Beware when overwriting existing files. Plain file overwrite is allowed only if the document was loaded with the same filename (and the same overloaded function), otherwise the destination file cannot be the same as the source file, because the destination file is truncated first and only then the source file content is copied into it.

See also
Write, WriteUpdate

This is an overloaded member function for your convenience.

◆ WriteUpdate() [2/2]

void PoDoFo::PdfMemDocument::WriteUpdate ( PdfOutputDevice pDevice,
bool  bTruncate = true 
)

Writes the document changes to an output device

Parameters
pDevicewrite to this output device
bTruncatewhether to truncate the pDevice first and fill it with the content of the source document; the default is true.

Writes the document changes to the output device as an incremental update. The document should be loaded with bForUpdate = true, otherwise an exception is thrown.

The bTruncate is used to determine whether saving to the same file or not. In case the bTruncate is true, a new source stream is opened and its whole content is copied to the pDevice first. Otherwise the pDevice is the same file which had been loaded and the caller is responsible to position the pDevice at the place, where the update should be written (basically at the end of the stream).

See also
Write, WriteUpdate

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.