pdfobjects::utils::Delinearizator Class Reference

#include <delinearizator.h>

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

List of all members.

Public Member Functions

int delinearize (const char *fileName)
int delinearize (FILE *file)

Static Public Member Functions

static boost::shared_ptr
< Delinearizator
getInstance (const char *fileName, IPdfWriter *pdfWriter)

Private Member Functions

 Delinearizator (FileStreamData &streamData, IPdfWriter *writer)
virtual ~Delinearizator ()
virtual int fillObjectList (IPdfWriter::ObjectList &objectList, int maxObjectCount)

Private Attributes

::Ref linearizedRef
int lastObj

Friends

class FileStreamDataDeleter< Delinearizator >

Detailed Description

Delinearizator class.

Provides functionality enabling correct changing linearized pdf documents to their unlinearized form. This may be very usefull especially if changes has to be done to document, because linearized document has rather strict rules and so can be easily broken by incremental changes.

Class reuses XRef class for low level pdf reading and parsing purpouses and adds logic related to linearized documents.

Output file will contain all objects - except those needed by linearized structure - in same format (e. g. filters in content streams), object and generation numbers.
Linearized documents are not prepared for multiversion documents very well (as mentioned before) and so output file will contain just one trailer and xref (so one revision). Format of this final section fully depends on given IPdfWriter implementator (set in constructor).

Usage
Use static factory method for instance creation:

 // we will use OldStylePdfWriter IPdfWriter implementator
 IPdfWriter * contentWriter=new OldStylePdfWriter();
 boost::shared_ptr<Delinearizator> delinearizator=DelinearizatorgetInstance(fileName, contentWriter);
 // check for encryption and set credentials if necessary
 if (delinearizator->isEncrypted())
 	delinearizator->setCredentials(ownerPasswd, userPasswd);
 // delinearize file content to file specified by name
 delinearizator->delinearize(outputFile);
 ...
 // instance is wrapped by the smart pointer so you don't
 // have bother with deallocation
 

Constructor & Destructor Documentation

pdfobjects::utils::Delinearizator::Delinearizator ( FileStreamData streamData,
IPdfWriter writer 
) [private]

Initialization constructor.

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

Delegates all the work to the PdfDocumentWriter constructor and additionaly checks whether document is linearized.

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

References pdfobjects::utils::checkLinearized(), linearizedRef, and pdfobjects::utils::FileStreamData::stream.

Referenced by getInstance().

virtual pdfobjects::utils::Delinearizator::~Delinearizator (  )  [inline, private, virtual]

Destructor.

Deallocates pdfWriter and delegates the rest to ~CXref.


Member Function Documentation

int pdfobjects::utils::Delinearizator::delinearize ( FILE *  file  ) 

Delinearizes pdf content to the given file.

Parameters:
file File handle where to put data.

Delegates to PdfDocumentWriter::writeDocument(FILE*).

Exceptions:
NotImplementedException if document is encrypted.
MalformedFormatExeption if the input file is currupted.

References lastObj, and pdfobjects::utils::PdfDocumentWriter::writeDocument().

int pdfobjects::utils::Delinearizator::delinearize ( const char *  fileName  ) 

Delinearizes pdf content to the given file.

Parameters:
fileName Output file name.

Delegates to PdfDocumentWriter::writeDocument(const char*).

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

References lastObj, and pdfobjects::utils::PdfDocumentWriter::writeDocument().

int pdfobjects::utils::Delinearizator::fillObjectList ( IPdfWriter::ObjectList objectList,
int  maxObjectCount 
) [private, virtual]

Provides all objects for delinearized document.

Parameters:
objectList Container for objects.
maxObjectCount Maximum objects count to be filled into the objectList.

Provides a deep copy of all objects availble in XRef::etries array except for Linearization dictionary. Consequential calls will continue from the last seen provided object.

Returns:
number of objects filled to the objectList.

Implements pdfobjects::utils::PdfDocumentWriter.

References debug::DBG_DBG, debug::DBG_ERR, pdfobjects::CXref::fetch(), xpdf::freeXpdfObject(), getInstance(), kernelPrintDbg, lastObj, linearizedRef, and utilsPrintDbg.

boost::shared_ptr< Delinearizator > pdfobjects::utils::Delinearizator::getInstance ( const char *  fileName,
IPdfWriter pdfWriter 
) [static]

Factory method for instance creation.

Parameters:
fileName Name of the pdf file.
pdfWriter Pdf content writer.

Creates FileStream from given fileName (file is open with `r' mode) and creates Delinearizator instance. Finally checks whether file is linearized and if not, prints error message and returns with NULL.
Smart pointer returned by this method contains a proper deleter which closes file handle created from given fileName.

Exceptions:
MalformedFormatExeption if file content is not valid pdf document.
Returns:
Delinearizator instance ready to be used or NULL, if given file is not linearized.

References debug::DBG_ERR, Delinearizator(), pdfobjects::utils::PdfDocumentWriter::getStreamData(), and utilsPrintDbg.

Referenced by fillObjectList().


Friends And Related Function Documentation

friend class FileStreamDataDeleter< Delinearizator > [friend]

Member Data Documentation

Marker of the last object returned by fillObjectList. Zeroed in writeDocument method.

Referenced by delinearize(), and fillObjectList().

Reference of linearized dictionary.

Referenced by Delinearizator(), and fillObjectList().


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