PoDoFo 0.9.20
Public Member Functions | Protected Member Functions | List of all members
PoDoFo::PdfMemDocument Class Referencefinal

#include <PdfMemDocument.h>

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

Public Member Functions

 PdfMemDocument ()
 
 PdfMemDocument (const PdfMemDocument &rhs)
 
void Load (const std::string_view &filename, const std::string_view &password={ })
 
void LoadFromBuffer (const bufferview &buffer, const std::string_view &password={ })
 
void LoadFromDevice (const std::shared_ptr< InputStreamDevice > &device, const std::string_view &password={ })
 
void Save (const std::string_view &filename, PdfSaveOptions opts=PdfSaveOptions::None)
 
void Save (OutputStreamDevice &device, PdfSaveOptions opts=PdfSaveOptions::None)
 
void SaveUpdate (const std::string_view &filename, PdfSaveOptions opts=PdfSaveOptions::None)
 
void SaveUpdate (OutputStreamDevice &device, PdfSaveOptions opts=PdfSaveOptions::None)
 
void AddPdfExtension (const PdfName &ns, int64_t level)
 
bool HasPdfExtension (const PdfName &ns, int64_t level) const
 
void RemovePdfExtension (const PdfName &ns, int64_t level)
 
std::vector< PdfExtensionGetPdfExtensions () const
 
void SetEncrypted (const std::string_view &userPassword, const std::string_view &ownerPassword, PdfPermissions protection=PdfPermissions::Default, PdfEncryptAlgorithm algorithm=PdfEncryptAlgorithm::AESV2, PdfKeyLength keyLength=PdfKeyLength::L40)
 
void SetEncrypt (std::unique_ptr< PdfEncrypt > &&encrypt)
 
void FreeObjectMemory (const PdfReference &ref, bool force=false)
 
void FreeObjectMemory (PdfObject *obj, bool force=false)
 
- Public Member Functions inherited from PoDoFo::PdfDocument
virtual ~PdfDocument ()
 
PdfOutlinesGetOrCreateOutlines ()
 
PdfNameTree & GetOrCreateNameTree ()
 
PdfAcroForm & GetOrCreateAcroForm (PdfAcroFormDefaulAppearance eDefaultAppearance=PdfAcroFormDefaulAppearance::BlackText12pt)
 
void AttachFile (const PdfFileSpec &fileSpec)
 
PdfFileSpecGetAttachment (const PdfString &name)
 
void AddNamedDestination (const PdfDestination &dest, const PdfString &name)
 
std::unique_ptr< PdfImageCreateImage (const std::string_view &prefix={ })
 
bool IsPrintAllowed () const
 
bool IsEditAllowed () const
 
bool IsCopyAllowed () const
 
bool IsEditNotesAllowed () const
 
bool IsFillAndSignAllowed () const
 
bool IsAccessibilityAllowed () const
 
bool IsDocAssemblyAllowed () const
 
bool IsHighPrintAllowed () const
 
bool IsEncrypted () const
 
PdfCatalog & GetCatalog ()
 
const PdfCatalog & GetCatalog () const
 
PdfPageCollectionGetPages ()
 
const PdfPageCollectionGetPages () const
 
PdfTrailer & GetTrailer ()
 
const PdfTrailer & GetTrailer () const
 
const PdfInfoGetInfo () const
 
PdfIndirectObjectListGetObjects ()
 
const PdfIndirectObjectListGetObjects () const
 

Protected Member Functions

void SetPdfVersion (PdfVersion version) override
 
PdfVersion GetPdfVersion () const override
 
- Protected Member Functions inherited from PoDoFo::PdfDocument
 PdfDocument (bool empty=false)
 
void SetTrailer (std::unique_ptr< PdfObject > obj)
 
void Init ()
 
void Clear ()
 

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 structur 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
PdfWriter

Constructor & Destructor Documentation

◆ PdfMemDocument() [1/2]

PdfMemDocument::PdfMemDocument ( )

Construct a new PdfMemDocument

◆ PdfMemDocument() [2/2]

PdfMemDocument::PdfMemDocument ( const PdfMemDocument rhs)

Construct a copy of the given document

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

◆ FreeObjectMemory() [1/2]

void PdfMemDocument::FreeObjectMemory ( const PdfReference ref,
bool  force = false 
)

Tries to free all memory allocated by the given PdfObject (variables and streams) and reads it from disk again if it is requested another time.

This will only work if load on demand is used. Other- wise any call to this method will be ignored. Load on demand is currently always enabled when using PdfMemDocument. If the object is dirty if will not be free'd.

Parameters
reffree all memory allocated by the object with this reference.
forceif true the object will be free'd even if IsDirty() returns true. So you will loose any changes made to this object.

This is an overloaded member for your convenience.

◆ FreeObjectMemory() [2/2]

void PdfMemDocument::FreeObjectMemory ( PdfObject obj,
bool  force = false 
)

Tries to free all memory allocated by the given PdfObject (variables and streams) and reads it from disk again if it is requested another time.

This will only work if load on demand is used. Other- wise any call to this method will be ignored. Load on demand is currently always enabled when using PdfMemDocument. If the object is dirty if will not be free'd.

Parameters
objfree object from memory
forceif true the object will be free'd even if IsDirty() returns true. So you will loose any changes made to this object.
See also
IsDirty

◆ 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 PdfName 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()

void 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

◆ LoadFromDevice()

void PdfMemDocument::LoadFromDevice ( 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

◆ RemovePdfExtension()

void PdfMemDocument::RemovePdfExtension ( const PdfName 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,
PdfEncryptAlgorithm  algorithm = PdfEncryptAlgorithm::AESV2,
PdfKeyLength  keyLength = PdfKeyLength::L40 
)

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.