/usr/include/podofo/base/PdfWriter.h is in libpodofo-dev 0.9.0-1.2+b2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | /***************************************************************************
* Copyright (C) 2005 by Dominik Seichter *
* domseichter@web.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef _PDF_WRITER_H_
#define _PDF_WRITER_H_
#include "PdfDefines.h"
#include "PdfOutputDevice.h"
#include "PdfVecObjects.h"
#include "PdfEncrypt.h"
namespace PoDoFo {
class PdfDictionary;
class PdfName;
class PdfObject;
class PdfPage;
class PdfPagesTree;
class PdfParser;
class PdfVecObjects;
class PdfXRef;
namespace NonPublic { class PdfHintStream; }
/** 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.
*/
class PODOFO_API PdfWriter {
public:
/** Create a PdfWriter object from a PdfParser object
* \param pParser a pdf parser object
*/
PdfWriter( PdfParser* pParser );
/** Create a new pdf file, from an vector of PdfObjects
* and a trailer object.
* \param pVecObjects the vector of objects
* \param pTrailer a valid trailer object
*/
PdfWriter( PdfVecObjects* pVecObjects, const PdfObject* pTrailer );
virtual ~PdfWriter();
/** Writes the complete document to a PDF file.
*
* \param pszFilename filename of a PDF file.
*/
void Write( const char* pszFilename );
#ifdef _WIN32
/** Writes the complete document to a PDF file.
*
* \param pszFilename filename of a PDF file.
*
* This is an overloaded member function to allow working
* with unicode characters. On Unix systes you can also path
* UTF-8 to the const char* overload.
*/
void Write( const wchar_t* pszFilename );
#endif // _WIN32
/** Writes the complete document to a PdfOutputDevice
*
* \param pDevice write to the specified device
*/
void Write( PdfOutputDevice* pDevice );
/** Set the write mode to use when writing the PDF.
* \param eWriteMode write mode
*/
void SetWriteMode( EPdfWriteMode eWriteMode ) { m_eWriteMode = eWriteMode; }
/** Get the write mode used for wirting the PDF
* \returns the write mode
*/
EPdfWriteMode GetWriteMode() const { return m_eWriteMode; }
/** Set the PDF Version of the document. Has to be called before Write() to
* have an effect.
* \param eVersion version of the pdf document
*/
void SetPdfVersion( EPdfVersion eVersion ) { m_eVersion = eVersion; }
/** Get the PDF version of the document
* \returns EPdfVersion version of the pdf document
*/
EPdfVersion GetPdfVersion() const { return m_eVersion; }
/** Enabled linearization for this document.
* I.e. optimize it for web usage. Default is false.
* \param bLinearize if true create a web optimized PDF file
*/
inline void SetLinearized( bool bLinearize );
/**
* \returns true if this PDF file is web optimized.
*/
inline bool GetLinearized() const;
/** Create a XRef stream which is in some case
* more compact but requires at least PDF 1.5
* Default is false.
* \param bStream if true a XRef stream object will be created
*/
inline void SetUseXRefStream( bool bStream );
/**
* \returns wether a XRef stream is used or not
*/
inline bool GetUseXRefStream() const;
/** Get the file format version of the pdf
* \returns the file format version as string
*/
const char* GetPdfVersionString() const { return s_szPdfVersionNums[static_cast<int>(m_eVersion)]; }
/** Set the written document to be encrypted using a PdfEncrypt object
*
* \param rEncrypt an encryption object which is used to encrypt the written PDF file
*/
void SetEncrypted( const PdfEncrypt & rEncrypt );
/**
* \returns true if this PdfWriter creates an encrypted PDF file
*/
bool GetEncrypted() const { return (m_pEncrypt != NULL); }
/** 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!
*
* \param pObject object to calculate the byte offset (has to be a
* child of this PdfWriter)
* \param pulOffset pointer to an unsigned long to save the offset
*/
void GetByteOffset( PdfObject* pObject, pdf_long* pulOffset );
/** Write the whole document to a buffer in memory.
*
* Better use a PdfOutputDevice that writes to a PdfRefCountedBuffer.
*
* \param ppBuffer will be malloc'ed and the document
* will be written to this buffer.
* \param pulLen the length of the buffer will be returned in this parameter
* \returns ErrOk on success
*
* \see Write
*/
void WriteToBuffer( char** ppBuffer, pdf_long* pulLen );
/** Add required keys to a trailer object
* \param pTrailer add keys to this object
* \param lSize number of objects in the PDF file
* \param bPrevEntry if true a prev entry is added to the trailer object with a value of 0
* \param bOnlySizeKey write only the size key
*/
void FillTrailerObject( PdfObject* pTrailer, pdf_long lSize, bool bPrevEntry, bool bOnlySizeKey ) const;
protected:
/**
* Create a PdfWriter from a PdfVecObjects
*/
PdfWriter( PdfVecObjects* pVecObjects );
/** Writes the pdf header to the current file.
* \param pDevice write to this output device
*/
void PODOFO_LOCAL WritePdfHeader( PdfOutputDevice* pDevice );
/** Write pdf objects to file
* \param pDevice write to this output device
* \param vecObjects write all objects in this vector to the file
* \param pXref add all written objects to this XRefTable
*/
void WritePdfObjects( PdfOutputDevice* pDevice, const PdfVecObjects& vecObjects, PdfXRef* pXref ) PODOFO_LOCAL;
/** 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.
*
* \param identifier write the identifier to this string
* \param pTrailer trailer object
*/
void CreateFileIdentifier( PdfString & identifier, const PdfObject* pTrailer ) const PODOFO_LOCAL;
private:
/** Writes a linearized PDF file
* \param pDevice write to this output device
*/
void PODOFO_LOCAL WriteLinearized( PdfOutputDevice* pDevice );
/** 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
*/
PdfObject* CreateLinearizationDictionary() PODOFO_LOCAL;
/** Reorder and renumber all object as required for linearized PDF files.
* This function is very slow.
*
* \param pLinearize linearization dictionary
* \param pHint primary hint stream dictionary
* \param pPage first page to display in the document
* \param ppLast the pointer will be initialized to the last object
* belonging to the first page
*/
//void ReorderObjectsLinearized( PdfObject* pLinearize, NonPublic::PdfHintStream* pHint, PdfPage* pPage, PdfObject** ppLast ) PODOFO_LOCAL;
/** Initialize m_pPagesTree with its correct value
* Always call this function befre accessing the pages tree.
*/
//void FetchPagesTree();
/** Find dependencies required for creating a linearized PDF of the catalog dictionary.
*/
//void FindCatalogDependencies( PdfObject* pCatalog, const PdfName & rName, TPdfReferenceList* pList, bool bWithDependencies ) PODOFO_LOCAL;
/** Fill all keys in the linearization dictionary with their values
* \param pLinearize a linearization dictionary
* \param pHint the hint stream
* \param pPage the first page in the linerarized PDF file
* \param pLast pointer of the last object belonging to the first page
* \param pVecXRefOffset xref table entries for previous entry
*/
// void FillLinearizationDictionary( PdfObject* pLinearize, PdfOutputDevice* pDevice, PdfPage* pPage, PdfObject* pLast, NonPublic::PdfHintStream* pHint, TVecXRefOffset* pVecXRefOffset ) PODOFO_LOCAL;
protected:
PdfVecObjects* m_vecObjects;
PdfObject* m_pTrailer;
bool m_bXRefStream;
PdfEncrypt* m_pEncrypt; ///< If not NULL encrypt all strings and streams and create an encryption dictionary in the trailer
PdfObject* m_pEncryptObj; ///< Used to temporarly store the encryption dictionary
PdfString m_identifier;
private:
EPdfWriteMode m_eWriteMode;
EPdfVersion m_eVersion;
bool m_bLinearized;
/**
* This value is required when writing
* a linearized PDF file.
* It represents the offset of the whitespace
* character before the first line in the XRef
* section.
*/
size_t m_lFirstInXRef;
size_t m_lLinearizedOffset;
size_t m_lLinearizedLastOffset;
size_t m_lTrailerOffset;
PdfVecObjects m_vecLinearized;
};
// -----------------------------------------------------
//
// -----------------------------------------------------
void PdfWriter::SetLinearized( bool bLinearize )
{
m_bLinearized = bLinearize;
}
// -----------------------------------------------------
//
// -----------------------------------------------------
bool PdfWriter::GetLinearized() const
{
return m_bLinearized;
}
// -----------------------------------------------------
//
// -----------------------------------------------------
void PdfWriter::SetUseXRefStream( bool bStream )
{
if( bStream && this->GetPdfVersion() < ePdfVersion_1_5 )
this->SetPdfVersion( ePdfVersion_1_5 );
m_bXRefStream = bStream;
}
// -----------------------------------------------------
//
// -----------------------------------------------------
bool PdfWriter::GetUseXRefStream() const
{
return m_bXRefStream;
}
};
#endif // _PDF_WRITER_H_
|