#include <pdfwriter.h>
Public Member Functions | |
| virtual | ~PdfDocumentWriter () |
| IPdfWriter * | setPdfWriter (IPdfWriter *pdfWriter) |
Static Public Member Functions | |
| static FileStreamData * | getStreamData (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 | |
| IPdfWriter * | pdfWriter |
Static Private Attributes | |
| static const int | writeBatchCount = 1000 |
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.
| pdfobjects::utils::PdfDocumentWriter::PdfDocumentWriter | ( | FileStreamData & | data, | |
| IPdfWriter * | pdfWriter | |||
| ) | [protected] |
Initialization constructor.
| 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).
| 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.
| virtual int pdfobjects::utils::PdfDocumentWriter::fillObjectList | ( | IPdfWriter::ObjectList & | objectList, | |
| int | maxObjectCount | |||
| ) | [protected, pure virtual] |
Abstract method to provide objects to be written.
| 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.
| 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.
| fileName | Name of the file to open. |
This method should be preferred way to provide constructor data parameter.
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.
| 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.
| int pdfobjects::utils::PdfDocumentWriter::writeDocument | ( | FILE * | file | ) | [protected, virtual] |
Writes a new document to the given file.
| 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).
| NotImplementedException | if document is encrypted. | |
| MalformedFormatExeption | if the input file is currupted. |
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.
| 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.
| 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().
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().