PoDoFo  0.9.6
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PoDoFo::PdfWriter Class Reference

#include <PdfWriter.h>

Inheritance diagram for PoDoFo::PdfWriter:
PoDoFo::PdfImmediateWriter

Public Member Functions

 PdfWriter (PdfParser *pParser)
 
 PdfWriter (PdfVecObjects *pVecObjects, const PdfObject *pTrailer)
 
void Write (const char *pszFilename)
 
void Write (PdfOutputDevice *pDevice)
 
void WriteUpdate (PdfOutputDevice *pDevice, PdfInputDevice *pSourceInputDevice, bool bRewriteXRefTable)
 
void SetWriteMode (EPdfWriteMode eWriteMode)
 
EPdfWriteMode GetWriteMode () const
 
void SetPdfVersion (EPdfVersion eVersion)
 
EPdfVersion GetPdfVersion () const
 
void SetLinearized (bool bLinearize)
 
bool GetLinearized () const
 
void SetUseXRefStream (bool bStream)
 
bool GetUseXRefStream () const
 
void SetPrevXRefOffset (pdf_int64 lPrevXRefOffset)
 
pdf_int64 GetPrevXRefOffset () const
 
void SetIncrementalUpdate (bool bIncrementalUpdate)
 
bool GetIncrementalUpdate (void) const
 
const char * GetPdfVersionString () const
 
void SetEncrypted (const PdfEncrypt &rEncrypt)
 
bool GetEncrypted () const
 
void GetByteOffset (PdfObject *pObject, pdf_long *pulOffset)
 
void WriteToBuffer (char **ppBuffer, pdf_long *pulLen)
 
void FillTrailerObject (PdfObject *pTrailer, pdf_long lSize, bool bOnlySizeKey) const
 

Protected Member Functions

 PdfWriter (PdfVecObjects *pVecObjects)
 
void PODOFO_LOCAL WritePdfHeader (PdfOutputDevice *pDevice)
 
void WritePdfObjects (PdfOutputDevice *pDevice, const PdfVecObjects &vecObjects, PdfXRef *pXref, bool bRewriteXRefTable=false) PODOFO_LOCAL
 
void CreateFileIdentifier (PdfString &identifier, const PdfObject *pTrailer, PdfString *pOriginalIdentifier=NULL) const PODOFO_LOCAL
 
void Write (PdfOutputDevice *pDevice, bool bRewriteXRefTable)
 
void PODOFO_LOCAL WriteLinearized (PdfOutputDevice *pDevice)
 
PdfObjectCreateLinearizationDictionary () PODOFO_LOCAL
 

Protected Attributes

PdfVecObjectsm_vecObjects
 
PdfEncryptm_pEncrypt
 If not NULL encrypt all strings and streams and create an encryption dictionary in the trailer.
 
PdfObjectm_pEncryptObj
 Used to temporarily store the encryption dictionary.
 

Detailed Description

The PdfWriter class writes a list of PdfObjects as PDF file. The XRef section (which is the required table of contents for any PDF file) is created automatically.

It does not know about pages but only about PdfObjects.

Most users will want to use PdfDocument.

Constructor & Destructor Documentation

◆ PdfWriter() [1/3]

PoDoFo::PdfWriter::PdfWriter ( PdfParser pParser)

Create a PdfWriter object from a PdfParser object

Parameters
pParsera pdf parser object

◆ PdfWriter() [2/3]

PoDoFo::PdfWriter::PdfWriter ( PdfVecObjects pVecObjects,
const PdfObject pTrailer 
)

Create a new pdf file, from an vector of PdfObjects and a trailer object.

Parameters
pVecObjectsthe vector of objects
pTrailera valid trailer object

◆ PdfWriter() [3/3]

PoDoFo::PdfWriter::PdfWriter ( PdfVecObjects pVecObjects)
protected

Create a PdfWriter from a PdfVecObjects

Member Function Documentation

◆ CreateFileIdentifier()

void PoDoFo::PdfWriter::CreateFileIdentifier ( PdfString identifier,
const PdfObject pTrailer,
PdfString pOriginalIdentifier = NULL 
) const
protected

Creates a file identifier which is required in several PDF workflows. All values from the files document information dictionary are used to create a unique MD5 key which is added to the trailer dictionary.

Parameters
identifierwrite the identifier to this string
pTrailertrailer object
pOriginalIdentifierwrite the original identifier (when using incremental update) to this string

◆ CreateLinearizationDictionary()

PdfObject* PoDoFo::PdfWriter::CreateLinearizationDictionary ( )
protected

Create a linearization dictionary for the current document and return a pointer to it after inserting it into the vector of PdfObjects

Returns
a pointer to the linearization dictionary

◆ FillTrailerObject()

void PoDoFo::PdfWriter::FillTrailerObject ( PdfObject pTrailer,
pdf_long  lSize,
bool  bOnlySizeKey 
) const

Add required keys to a trailer object

Parameters
pTraileradd keys to this object
lSizenumber of objects in the PDF file
bOnlySizeKeywrite only the size key

◆ GetByteOffset()

void PoDoFo::PdfWriter::GetByteOffset ( PdfObject pObject,
pdf_long *  pulOffset 
)

Calculate the byte offset of the object pObject in the PDF file if the file was written to disk at the moment of calling this function.

This function is very calculation intensive!

Parameters
pObjectobject to calculate the byte offset (has to be a child of this PdfWriter)
pulOffsetpointer to an unsigned long to save the offset

◆ GetEncrypted()

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

◆ GetIncrementalUpdate()

bool PoDoFo::PdfWriter::GetIncrementalUpdate ( void  ) const
inline
Returns
whether writing an incremental update

◆ GetLinearized()

bool PoDoFo::PdfWriter::GetLinearized ( ) const
inline
Returns
true if this PDF file is web optimized.

◆ GetPdfVersion()

EPdfVersion PoDoFo::PdfWriter::GetPdfVersion ( ) const
inline

Get the PDF version of the document

Returns
EPdfVersion version of the pdf document

◆ GetPdfVersionString()

const char* PoDoFo::PdfWriter::GetPdfVersionString ( ) const
inline

Get the file format version of the pdf

Returns
the file format version as string

◆ GetPrevXRefOffset()

pdf_int64 PoDoFo::PdfWriter::GetPrevXRefOffset ( ) const
inline
Returns
offset to the previous XRef table, as previously set by SetPrevXRefOffset.
See also
SetPrevXRefOffset

◆ GetUseXRefStream()

bool PoDoFo::PdfWriter::GetUseXRefStream ( ) const
inline
Returns
whether an XRef stream is used or not

◆ GetWriteMode()

EPdfWriteMode PoDoFo::PdfWriter::GetWriteMode ( ) const
inline

Get the write mode used for writing the PDF

Returns
the write mode

◆ SetEncrypted()

void PoDoFo::PdfWriter::SetEncrypted ( const PdfEncrypt rEncrypt)

Set the written document to be encrypted using a PdfEncrypt object

Parameters
rEncryptan encryption object which is used to encrypt the written PDF file

◆ SetIncrementalUpdate()

void PoDoFo::PdfWriter::SetIncrementalUpdate ( bool  bIncrementalUpdate)
inline

Set whether writing an incremental update. Default is false.

Parameters
bIncrementalUpdateif true an incremental update will be written

◆ SetLinearized()

void PoDoFo::PdfWriter::SetLinearized ( bool  bLinearize)
inline

Enabled linearization for this document. I.e. optimize it for web usage. Default is false.

Parameters
bLinearizeif true create a web optimized PDF file

◆ SetPdfVersion()

void PoDoFo::PdfWriter::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

◆ SetPrevXRefOffset()

void PoDoFo::PdfWriter::SetPrevXRefOffset ( pdf_int64  lPrevXRefOffset)
inline

Sets an offset to the previous XRef table. Set it to lower than or equal to 0, to not write a reference to the previous XRef table. The default is 0.

Parameters
lPrevXRefOffsetthe previous XRef table offset

◆ SetUseXRefStream()

void PoDoFo::PdfWriter::SetUseXRefStream ( bool  bStream)
inline

Create a XRef stream which is in some case more compact but requires at least PDF 1.5 Default is false.

Parameters
bStreamif true a XRef stream object will be created

◆ SetWriteMode()

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

Set the write mode to use when writing the PDF.

Parameters
eWriteModewrite mode

◆ Write() [1/3]

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

Writes the complete document to a PDF file.

Parameters
pszFilenamefilename of a PDF file.

◆ Write() [2/3]

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

Writes the complete document to a PdfOutputDevice

Parameters
pDevicewrite to the specified device
See also
WriteUpdate

◆ Write() [3/3]

void PoDoFo::PdfWriter::Write ( PdfOutputDevice pDevice,
bool  bRewriteXRefTable 
)
protected

Internal implementation of the Write() call with the common code

Parameters
pDevicewrite to this output device
bRewriteXRefTablewhether will rewrite whole XRef table (used only if GetIncrementalUpdate() returns true)

◆ WriteLinearized()

void PoDoFo::PdfWriter::WriteLinearized ( PdfOutputDevice pDevice)
protected

Writes a linearized PDF file

Parameters
pDevicewrite to this output device

◆ WritePdfHeader()

void PoDoFo::PdfWriter::WritePdfHeader ( PdfOutputDevice pDevice)
protected

Writes the pdf header to the current file.

Parameters
pDevicewrite to this output device

◆ WritePdfObjects()

void PoDoFo::PdfWriter::WritePdfObjects ( PdfOutputDevice pDevice,
const PdfVecObjects vecObjects,
PdfXRef pXref,
bool  bRewriteXRefTable = false 
)
protected

Write pdf objects to file

Parameters
pDevicewrite to this output device
vecObjectswrite all objects in this vector to the file
pXrefadd all written objects to this XRefTable
bRewriteXRefTablewhether will rewrite whole XRef table (used only if GetIncrementalUpdate() returns true)

◆ WriteToBuffer()

void PoDoFo::PdfWriter::WriteToBuffer ( char **  ppBuffer,
pdf_long *  pulLen 
)

Write the whole document to a buffer in memory.

Better use a PdfOutputDevice that writes to a PdfRefCountedBuffer.

Parameters
ppBufferwhere this points the address of the buffer will be written after that being malloc()'d and the document will be written to that buffer.
pulLenthe buffer length will be returned in this parameter
See also
Write

◆ WriteUpdate()

void PoDoFo::PdfWriter::WriteUpdate ( PdfOutputDevice pDevice,
PdfInputDevice pSourceInputDevice,
bool  bRewriteXRefTable 
)

Writes the document changes to an output device

Parameters
pDevicewrite to the specified device
pSourceInputDevicewhere to copy original content from; can be NULL
bRewriteXRefTablewhether to rewrite whole XRef table

Writes an incremental update to the pDevice, using the pSourceInputDevice content as the original file content. When the pSourceInputDevice is NULL, the caller is responsible to have the pDevice filled with the previous content and to have it positioned at the end of the stream.

Calling this also switches the writer to the incremental update mode.

See also
SetIncrementalUpdate

Member Data Documentation

◆ m_vecObjects

PdfVecObjects* PoDoFo::PdfWriter::m_vecObjects
protected

Reorder and renumber all object as required for linearized PDF files. This function is very slow.

Parameters
pLinearizelinearization dictionary
pHintprimary hint stream dictionary
pPagefirst page to display in the document
ppLastthe pointer will be initialized to the last object belonging to the first page Initialize m_pPagesTree with its correct value Always call this function before accessing the pages tree. Find dependencies required for creating a linearized PDF of the catalog dictionary. Fill all keys in the linearization dictionary with their values
pLinearizea linearization dictionary
pHintthe hint stream
pPagethe first page in the linearized PDF file
pLastpointer of the last object belonging to the first page
pVecXRefOffsetxref table entries for previous entry