PoDoFo 0.9.20
Public Member Functions | List of all members
PoDoFo::PdfParser Class Reference

#include <PdfParser.h>

Public Member Functions

 PdfParser (PdfIndirectObjectList &objects)
 
 ~PdfParser ()
 
void Parse (InputStreamDevice &device, bool loadOnDemand=true)
 
bool IsEncrypted () const
 
void SetPassword (const std::string_view &password)
 
int GetNumberOfIncrementalUpdates () const
 
const PdfIndirectObjectListGetObjects () const
 
PdfVersion GetPdfVersion () const
 
bool GetLoadOnDemand () const
 
size_t GetFileSize () const
 
const PdfEncryptGetEncrypt () const
 
bool IsStrictParsing () const
 
void SetStrictParsing (bool strict)
 
bool GetIgnoreBrokenObjects () const
 
void SetIgnoreBrokenObjects (bool broken)
 

Detailed Description

PdfParser reads a PDF file into memory. The file can be modified in memory and written back using the PdfWriter class. Most PDF features are supported

Constructor & Destructor Documentation

◆ PdfParser()

PdfParser::PdfParser ( PdfIndirectObjectList objects)

Create a new PdfParser object You have to open a PDF file using ParseFile later.

Parameters
objectsvector to write the parsed PdfObjects to
See also
ParseFile

◆ ~PdfParser()

PdfParser::~PdfParser ( )

Delete the PdfParser and all PdfObjects

Member Function Documentation

◆ GetEncrypt()

const PdfEncrypt * PoDoFo::PdfParser::GetEncrypt ( ) const
inline
Returns
the parsers encryption object or nullptr if the read PDF file was not encrypted

◆ GetFileSize()

size_t PoDoFo::PdfParser::GetFileSize ( ) const
inline
Returns
the length of the file

◆ GetIgnoreBrokenObjects()

bool PoDoFo::PdfParser::GetIgnoreBrokenObjects ( ) const
inline
Returns
if broken objects are ignored while parsing

◆ GetLoadOnDemand()

bool PoDoFo::PdfParser::GetLoadOnDemand ( ) const
inline
Returns
true if this PdfParser loads all objects on demand at the time they are accessed first. The default is to load all object immediately. In this case false is returned.

◆ GetNumberOfIncrementalUpdates()

int PoDoFo::PdfParser::GetNumberOfIncrementalUpdates ( ) const
inline

Retrieve the number of incremental updates that have been applied to the last parsed PDF file.

0 means no update has been applied.

Returns
the number of incremental updates to the parsed PDF.

◆ GetObjects()

const PdfIndirectObjectList * PoDoFo::PdfParser::GetObjects ( ) const
inline

Get a reference to the sorted internal objects vector.

Returns
the internal objects vector.

◆ GetPdfVersion()

PdfVersion PoDoFo::PdfParser::GetPdfVersion ( ) const
inline

Get the file format version of the pdf

Returns
the file format version as enum

◆ IsEncrypted()

bool PdfParser::IsEncrypted ( ) const
Returns
true if this PdfWriter creates an encrypted PDF file

◆ IsStrictParsing()

bool PoDoFo::PdfParser::IsStrictParsing ( ) const
inline
Returns
true if strict parsing mode is enabled
See also
SetStringParsing

◆ Parse()

void PdfParser::Parse ( InputStreamDevice device,
bool  loadOnDemand = true 
)

Open a PDF file and parse it.

Parameters
devicethe input device to read from
loadOnDemandIf true all objects will be read from the file at the time they are accessed first. If false all objects will be read immediately. This is faster if you do not need the complete PDF file in memory.

This might throw a PdfError( PdfErrorCode::InvalidPassword ) exception if a password is required to read this PDF. Call SetPassword() with the correct password in this case.

See also
SetPassword

◆ SetIgnoreBrokenObjects()

void PoDoFo::PdfParser::SetIgnoreBrokenObjects ( bool  broken)
inline

Specify if the parser should ignore broken objects, i.e. XRef entries that do not point to valid objects.

Default is to ignore broken objects and to not throw an exception if one is found.

Parameters
bBrokenif true broken objects will be ignored

◆ SetPassword()

void PoDoFo::PdfParser::SetPassword ( const std::string_view &  password)
inline

If you try to open an encrypted PDF file, which requires a password to open, PoDoFo will throw a PdfError( PdfErrorCode::InvalidPassword ) exception.

If you got such an exception, you have to set a password which should be used for opening the PDF.

The usual way will be to ask the user for the password and set the password using this method.

PdfParser will immediately continue to read the PDF file.

Parameters
passworda user or owner password which can be used to open an encrypted PDF file If the password is invalid, a PdfError( PdfErrorCode::InvalidPassword ) exception is thrown!

◆ SetStrictParsing()

void PoDoFo::PdfParser::SetStrictParsing ( bool  strict)
inline

Enable/disable strict parsing mode. Strict parsing is by default disabled.

If you enable strict parsing, PoDoFo will fail on a few more common PDF failures. Please note that PoDoFo's parser is by default very strict already and does not recover from e.g. wrong XREF tables.

Parameters
strictnew setting for strict parsing mode.