PoDoFo  1.0.0-dev
Public Member Functions | Protected Member Functions | List of all members
PoDoFo::PdfMemDocument Class Referencefinal

PdfMemDocument is the core class for reading and manipulating PDF files and writing them back to disk. More...

#include <PdfMemDocument.h>

Inheritance diagram for PoDoFo::PdfMemDocument:
PoDoFo::PdfDocument

Public Member Functions

 PdfMemDocument ()
 Construct a new PdfMemDocument.
 
 PdfMemDocument (const std::shared_ptr< InputStreamDevice > &device, const std::string_view &password={ })
 
 PdfMemDocument (const PdfMemDocument &rhs)
 Construct a copy of the given document.
 
void Load (const std::string_view &filename, const std::string_view &password={ })
 Load a PdfMemDocument from a file. More...
 
void LoadFromBuffer (const bufferview &buffer, const std::string_view &password={ })
 Load a PdfMemDocument from a buffer in memory. More...
 
void Load (const std::shared_ptr< InputStreamDevice > &device, const std::string_view &password={ })
 Load a PdfMemDocument from a PdfRefCountedInputDevice. More...
 
void Save (const std::string_view &filename, PdfSaveOptions opts=PdfSaveOptions::None)
 Save the complete document to a file. More...
 
void Save (OutputStreamDevice &device, PdfSaveOptions opts=PdfSaveOptions::None)
 Save the complete document to an output device. More...
 
void SaveUpdate (const std::string_view &filename, PdfSaveOptions opts=PdfSaveOptions::None)
 Save the document changes to a file. More...
 
void SaveUpdate (OutputStreamDevice &device, PdfSaveOptions opts=PdfSaveOptions::None)
 Save the document changes to an output device. More...
 
void AddPdfExtension (const PdfName &ns, int64_t level)
 Add a vendor-specific extension to the current PDF version. More...
 
bool HasPdfExtension (const std::string_view &ns, int64_t level) const
 Checks whether the documents is tagged to imlpement a vendor-specific extension to the current PDF version. More...
 
void RemovePdfExtension (const std::string_view &ns, int64_t level)
 Remove a vendor-specific extension to the current PDF version. More...
 
std::vector< PdfExtensionGetPdfExtensions () const
 Return the list of all vendor-specific extensions to the current PDF version. More...
 
void SetEncrypted (const std::string_view &userPassword, const std::string_view &ownerPassword, PdfPermissions protection=PdfPermissions::Default, PdfEncryptionAlgorithm algorithm=PdfEncryptionAlgorithm::AESV2, PdfKeyLength keyLength=PdfKeyLength::L128)
 Encrypt the document during writing. More...
 
void SetEncrypt (std::unique_ptr< PdfEncrypt > &&encrypt)
 Encrypt the document during writing using a PdfEncrypt object. More...
 
const PdfEncryptGetEncrypt () const override
 
- Public Member Functions inherited from PoDoFo::PdfDocument
virtual ~PdfDocument ()
 Close down/destruct the PdfDocument.
 
PdfOutlinesGetOrCreateOutlines ()
 Get access to the Outlines (Bookmarks) dictionary The returned outlines object is owned by the PdfDocument. More...
 
PdfNameTreesGetOrCreateNames ()
 Get access to the Names dictionary (where all the named objects are stored) The returned PdfNameTrees object is owned by the PdfDocument. More...
 
PdfAcroForm & GetOrCreateAcroForm (PdfAcroFormDefaulAppearance eDefaultAppearance=PdfAcroFormDefaulAppearance::ArialBlack)
 Get access to the AcroForm dictionary. More...
 
void CollectGarbage ()
 
std::unique_ptr< PdfImageCreateImage ()
 Construct a new PdfImage object.
 
std::unique_ptr< PdfXObjectForm > CreateXObjectForm (const Rect &rect)
 
std::unique_ptr< PdfDestinationCreateDestination ()
 
std::unique_ptr< PdfColorSpace > CreateColorSpace (const PdfColorSpaceFilterPtr &filter)
 
std::unique_ptr< PdfExtGStateCreateExtGState ()
 
template<typename Taction >
std::unique_ptr< Taction > CreateAction ()
 
std::unique_ptr< PdfActionCreateAction (PdfActionType type)
 
std::unique_ptr< PdfFileSpecCreateFileSpec ()
 
bool IsPrintAllowed () const
 Checks if printing this document is allowed. More...
 
bool IsEditAllowed () const
 Checks if modifying this document (besides annotations, form fields or substituting pages) is allowed. More...
 
bool IsCopyAllowed () const
 Checks if text and graphics extraction is allowed. More...
 
bool IsEditNotesAllowed () const
 Checks if it is allowed to add or modify annotations or form fields. More...
 
bool IsFillAndSignAllowed () const
 Checks if it is allowed to fill in existing form or signature fields. More...
 
bool IsAccessibilityAllowed () const
 Checks if it is allowed to extract text and graphics to support users with disabilities. More...
 
bool IsDocAssemblyAllowed () const
 Checks if it is allowed to insert, create, rotate, or delete pages or add bookmarks. More...
 
bool IsHighPrintAllowed () const
 Checks if it is allowed to print a high quality version of this document Every PDF-consuming application has to adhere to this value! More...
 
PdfAcroForm & MustGetAcroForm ()
 
const PdfAcroForm & MustGetAcroForm () const
 
PdfNameTreesMustGetNames ()
 
const PdfNameTreesMustGetNames () const
 
PdfOutlinesMustGetOutlines ()
 
const PdfOutlinesMustGetOutlines () const
 
PdfDocumentFieldIterable GetFieldsIterator ()
 Get an iterator for all fields in the document. More...
 
PdfDocumentConstFieldIterable GetFieldsIterator () const
 
void Reset ()
 Clear all internal structures and reset PdfDocument to an empty state.
 
bool IsEncrypted () const
 
PdfCatalog & GetCatalog ()
 Get access to the internal Catalog dictionary or root object. More...
 
const PdfCatalog & GetCatalog () const
 Get access to the internal Catalog dictionary or root object. More...
 
PdfPageCollectionGetPages ()
 Get access to the page tree. More...
 
const PdfPageCollectionGetPages () const
 Get access to the page tree. More...
 
PdfTrailer & GetTrailer ()
 Get access to the internal trailer dictionary or root object. More...
 
const PdfTrailer & GetTrailer () const
 Get access to the internal trailer dictionary or root object. More...
 
const PdfInfoGetInfo () const
 Get access to the internal Info dictionary You can set the author, title etc. More...
 
PdfMetadata & GetMetadata ()
 
const PdfMetadata & GetMetadata () const
 
PdfIndirectObjectListGetObjects ()
 Get access to the internal vector of objects or root object. More...
 
const PdfIndirectObjectListGetObjects () const
 Get access to the internal vector of objects or root object. More...
 
PdfAcroForm * GetAcroForm ()
 
const PdfAcroForm * GetAcroForm () const
 
PdfNameTreesGetNames ()
 
const PdfNameTreesGetNames () const
 
PdfOutlinesGetOutlines ()
 
const PdfOutlinesGetOutlines () const
 
PdfFontManagerGetFonts ()
 
template<typename TAction >
std::unique_ptr< TAction > CreateAction ()
 

Protected Member Functions

void SetPdfVersion (PdfVersion version) override
 Set the PDF Version of the document. More...
 
PdfVersion GetPdfVersion () const override
 Get the PDF version of the document. More...
 
- Protected Member Functions inherited from PoDoFo::PdfDocument
 PdfDocument (bool empty=false)
 Construct a new (empty) PdfDocument. More...
 
 PdfDocument (const PdfDocument &doc)
 
void SetTrailer (std::unique_ptr< PdfObject > obj)
 Set the trailer of this PdfDocument deleting the old one. More...
 
void Init ()
 Internal method for initializing the pages tree for this document.
 
void Clear ()
 Clear all variables that have internal memory usage.
 

Detailed Description

PdfMemDocument is the core class for reading and manipulating PDF files and writing them back to disk.

PdfMemDocument was designed to allow easy access to the object structure of a PDF file.

PdfMemDocument should be used whenever you want to change the object structure of a PDF file.

When you are only creating PDF files, please use PdfStreamedDocument which is usually faster for creating PDFs.

See also
PdfDocument
PdfStreamedDocument
PdfParser

Member Function Documentation

◆ AddPdfExtension()

void PdfMemDocument::AddPdfExtension ( const PdfName ns,
int64_t  level 
)

Add a vendor-specific extension to the current PDF version.

Parameters
nsnamespace of the extension
levellevel of the extension

◆ GetPdfExtensions()

vector< PdfExtension > PdfMemDocument::GetPdfExtensions ( ) const

Return the list of all vendor-specific extensions to the current PDF version.

Parameters
nsnamespace of the extension
levellevel of the extension

◆ GetPdfVersion()

PdfVersion PdfMemDocument::GetPdfVersion ( ) const
overrideprotectedvirtual

Get the PDF version of the document.

Returns
PdfVersion version of the pdf document

Implements PoDoFo::PdfDocument.

◆ HasPdfExtension()

bool PdfMemDocument::HasPdfExtension ( const std::string_view &  ns,
int64_t  level 
) const

Checks whether the documents is tagged to imlpement a vendor-specific extension to the current PDF version.

Parameters
nsnamespace of the extension
levellevel of the extension

◆ Load() [1/2]

void PoDoFo::PdfMemDocument::Load ( const std::shared_ptr< InputStreamDevice > &  device,
const std::string_view &  password = { } 
)

Load a PdfMemDocument from a PdfRefCountedInputDevice.

Parameters
devicethe input device containing the PDF
See also
WriteUpdate, Load, LoadFromBuffer

◆ Load() [2/2]

void PoDoFo::PdfMemDocument::Load ( const std::string_view &  filename,
const std::string_view &  password = { } 
)

Load a PdfMemDocument from a file.

Parameters
filenamefilename of the file which is going to be parsed/opened

When the bForUpdate is set to true, the filename is copied for later use by WriteUpdate.

See also
WriteUpdate, LoadFromBuffer, LoadFromDevice

◆ LoadFromBuffer()

void PdfMemDocument::LoadFromBuffer ( const bufferview buffer,
const std::string_view &  password = { } 
)

Load a PdfMemDocument from a buffer in memory.

Parameters
buffera memory area containing the PDF data
See also
WriteUpdate, Load, LoadFromDevice

◆ RemovePdfExtension()

void PdfMemDocument::RemovePdfExtension ( const std::string_view &  ns,
int64_t  level 
)

Remove a vendor-specific extension to the current PDF version.

Parameters
nsnamespace of the extension
levellevel of the extension

◆ Save() [1/2]

void PoDoFo::PdfMemDocument::Save ( const std::string_view &  filename,
PdfSaveOptions  opts = PdfSaveOptions::None 
)

Save the complete document to a file.

Parameters
filenamefilename of the document
See also
Save, SaveUpdate

This is an overloaded member function for your convenience.

◆ Save() [2/2]

void PdfMemDocument::Save ( OutputStreamDevice &  device,
PdfSaveOptions  opts = PdfSaveOptions::None 
)

Save the complete document to an output device.

Parameters
devicewrite to this output device
See also
SaveUpdate

◆ SaveUpdate() [1/2]

void PoDoFo::PdfMemDocument::SaveUpdate ( const std::string_view &  filename,
PdfSaveOptions  opts = PdfSaveOptions::None 
)

Save the document changes to a file.

Parameters
filenamefilename of the document

Writes the document changes to a file as an incremental update. The document should be loaded with bForUpdate = true, otherwise an exception is thrown.

Beware when overwriting existing files. Plain file overwrite is allowed only if the document was loaded with the same filename (and the same overloaded function), otherwise the destination file cannot be the same as the source file, because the destination file is truncated first and only then the source file content is copied into it.

See also
Save, SaveUpdate

This is an overloaded member function for your convenience.

◆ SaveUpdate() [2/2]

void PdfMemDocument::SaveUpdate ( OutputStreamDevice &  device,
PdfSaveOptions  opts = PdfSaveOptions::None 
)

Save the document changes to an output device.

Parameters
devicewrite to this output device

Writes the document changes to the output device as an incremental update. The document should be loaded with bForUpdate = true, otherwise an exception is thrown.

See also
Save, SaveUpdate

◆ SetEncrypt()

void PdfMemDocument::SetEncrypt ( std::unique_ptr< PdfEncrypt > &&  encrypt)

Encrypt the document during writing using a PdfEncrypt object.

Parameters
encryptan encryption object that will be owned by PdfMemDocument

◆ SetEncrypted()

void PdfMemDocument::SetEncrypted ( const std::string_view &  userPassword,
const std::string_view &  ownerPassword,
PdfPermissions  protection = PdfPermissions::Default,
PdfEncryptionAlgorithm  algorithm = PdfEncryptionAlgorithm::AESV2,
PdfKeyLength  keyLength = PdfKeyLength::L128 
)

Encrypt the document during writing.

Parameters
userPasswordthe user password (if empty the user does not have to enter a password to open the document)
ownerPasswordthe owner password
protectionseveral PdfPermissions values or'ed together to set the users permissions for this document
algorithmthe revision of the encryption algorithm to be used
keyLengththe length of the encryption key ranging from 40 to 256 bits (only used if algorithm >= PdfEncryptAlgorithm::RC4V2)
See also
PdfEncrypt

◆ SetPdfVersion()

void PdfMemDocument::SetPdfVersion ( PdfVersion  version)
overrideprotectedvirtual

Set the PDF Version of the document.

Has to be called before Write() to have an effect.

Parameters
versionversion of the pdf document

Implements PoDoFo::PdfDocument.


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