pdfobjects::utils::PdfDocumentWriter Class Reference

#include <pdfwriter.h>

Inheritance diagram for pdfobjects::utils::PdfDocumentWriter:
pdfobjects::CXref pdfobjects::utils::Delinearizator pdfobjects::utils::Flattener

List of all members.

Public Member Functions

virtual ~PdfDocumentWriter ()
IPdfWritersetPdfWriter (IPdfWriter *pdfWriter)

Static Public Member Functions

static FileStreamDatagetStreamData (const char *fileName)

Protected Member Functions

virtual int fillObjectList (IPdfWriter::ObjectList &objectList, int maxObjectCount)=0
virtual int writeDocument (const char *fileName)
virtual int writeDocument (FILE *file)
 PdfDocumentWriter (FileStreamData &data, IPdfWriter *pdfWriter)

Protected Attributes

IPdfWriterpdfWriter

Static Private Attributes

static const int writeBatchCount = 1000

Detailed Description

Generic class to PDF document writing. The main responsibility of this class is to provide unified interface for arbitrary PDF document writing (note that this limits to complete documents - so it doesn't include incremental update document writing).
Class is meant to be base type for other specialized document writers which are supposed to implement fillObjectList abstract class. All other document structure related issues are already implemented in this class.
Note that the class doesn't write content of the file direct but it uses IPdfWriter provided in construtor or by setPdfWriter instead.


Constructor & Destructor Documentation

pdfobjects::utils::PdfDocumentWriter::PdfDocumentWriter ( FileStreamData data,
IPdfWriter pdfWriter 
) [protected]

Initialization constructor.

Parameters:
streamData Input stream data.
writer Pdf content writer.

Uses CXref(BaseStream *) constructor and initializes file handle and pdfWriter with given one (pdfWriter has to be allocated by new operator, because it is deallocated by delete in destructor - if NULL is provided, writeDocument methods do nothing).

Exceptions:
MalformedFormatExeption if file content is not valid pdf document.

References pdfobjects::utils::FileStreamData::file, and pdfobjects::utils::FileStreamData::stream.

pdfobjects::utils::PdfDocumentWriter::~PdfDocumentWriter (  )  [virtual]

Destructor.

Destroys CXref internal data and deallocates pdfWriter. Note that file handle provided to the constructor has to be closed by descendants and it has to be closed after the instance is destroyed. FileStreamDataDeleter is the preferred way to do that.

References pdfWriter.


Member Function Documentation

virtual int pdfobjects::utils::PdfDocumentWriter::fillObjectList ( IPdfWriter::ObjectList objectList,
int  maxObjectCount 
) [protected, pure virtual]

Abstract method to provide objects to be written.

Parameters:
objectList List of objects to be filled.
maxObjectCount Maximum number of objects to be filled.

This method is called by writeDocument until it returns no objects. Implementation may clear the list before it adds new elements but is must provide up to given maxObjectCount. Use maxObjectCount=0 for unlimited number of objects.

Returns:
Number of objects added to given objectList.
Exceptions:
MalformedFormatExeption if the document content is not valid.

Implemented in pdfobjects::utils::Delinearizator, and pdfobjects::utils::Flattener.

Referenced by writeDocument().

FileStreamData * pdfobjects::utils::PdfDocumentWriter::getStreamData ( const char *  fileName  )  [static]

Opens file and creates StreamData.

Parameters:
fileName Name of the file to open.

This method should be preferred way to provide constructor data parameter.

Returns:
StreamData which contains opened stream and file handle or NULL if not able to open file for reading.

References debug::DBG_DBG, debug::DBG_ERR, pdfobjects::utils::FileStreamData::file, pdfobjects::utils::FileStreamData::stream, and utilsPrintDbg.

Referenced by pdfobjects::utils::Flattener::getInstance(), and pdfobjects::utils::Delinearizator::getInstance().

IPdfWriter* pdfobjects::utils::PdfDocumentWriter::setPdfWriter ( IPdfWriter pdfWriter  )  [inline]

Sets new pdf content writer.

Parameters:
pdfWriter IPdfWriter interface implementator.

If given parameter is not NULL, sets new value of pdfWriter field and returns an old one. Otherwise just returns current one.
NOTE that caller is responsible for deallocation if provides new one.

Returns:
Currently set implementator or old value if parameter is non NULL.
int pdfobjects::utils::PdfDocumentWriter::writeDocument ( FILE *  file  )  [protected, virtual]

Writes a new document to the given file.

Parameters:
file Opened file handle where to write.

Sets position to the file beginning and writes the same pdf header as in the original stream. Then writes all objects provided by fillObjectList (calls this method repeatedly unless 0 objects are returned). Finally stores xref and trailer section.
Caller is responsible for file handle closing.
NOTE that method doesn't check whether given file is same as the one used for input data. If it refers to same file, result is unpredictable.
Returns with erro (EINVAL) if no pdfWriter is specified (it is NULL).

Returns:
0 if everything ok, otherwise value of error of the error.
Exceptions:
NotImplementedException if document is encrypted.
MalformedFormatExeption if the input file is currupted.
Returns:
0 on success, errno otherwise.

References debug::DBG_DBG, debug::DBG_ERR, debug::DBG_INFO, fillObjectList(), xpdf::freeXpdfObject(), pdfobjects::CXref::getNeedCredentials(), pdfobjects::CXref::getTrailerDict(), pdfobjects::utils::isEncrypted(), pdfWriter, utilsPrintDbg, writeBatchCount, pdfobjects::utils::IPdfWriter::writeContent(), pdfobjects::utils::IPdfWriter::writeHeader(), and pdfobjects::utils::IPdfWriter::writeTrailer().

int pdfobjects::utils::PdfDocumentWriter::writeDocument ( const char *  fileName  )  [protected, virtual]

Opens output file and writes a new document to it.

Parameters:
fileName File to be opened.

Opens given file (in trucate mode) and delegates the rest to delinearize(FILE *) method. If given file doesn't exist, it will be created. Finally closes file.

Returns:
0 on success, errno otherwise.
Exceptions:
NotImplementedException if document is encrypted.

References debug::DBG_DBG, debug::DBG_ERR, and utilsPrintDbg.

Referenced by pdfobjects::utils::Delinearizator::delinearize(), and pdfobjects::utils::Flattener::flatten().


Member Data Documentation

Pdf content writer implementator.

All writing of pdf content is delegated to this object.

Referenced by writeDocument(), and ~PdfDocumentWriter().

const int pdfobjects::utils::PdfDocumentWriter::writeBatchCount = 1000 [static, private]

Number of objects that should be written in one batch. This constant is used as the maxObjectCount parameter to fillObjectList method.

Referenced by writeDocument().


The documentation for this class was generated from the following files: