pdfmm 0.9.20
Public Member Functions | Protected Member Functions | List of all members
mm::PdfDocument Class Referenceabstract

#include <PdfDocument.h>

Inheritance diagram for mm::PdfDocument:
mm::PdfMemDocument mm::PdfStreamedDocument

Public Member Functions

virtual ~PdfDocument ()
 
virtual PdfVersion GetPdfVersion () const =0
 
virtual bool IsLinearized () const =0
 
PdfOutlinesGetOrCreateOutlines ()
 
PdfNameTree & GetOrCreateNameTree ()
 
PdfAcroForm & GetOrCreateAcroForm (PdfAcroFormDefaulAppearance eDefaultAppearance=PdfAcroFormDefaulAppearance::BlackText12pt)
 
void EmbedSubsetFonts ()
 
const PdfDocumentAppend (const PdfDocument &doc, bool appendAll=true)
 
const PdfDocumentInsertExistingPageAt (const PdfDocument &doc, unsigned pageIndex, unsigned atIndex)
 
PdfRect FillXObjectFromDocumentPage (PdfXObject &xobj, const PdfDocument &doc, unsigned pageIndex, bool useTrimBox)
 
PdfRect FillXObjectFromExistingPage (PdfXObject &xobj, unsigned pageIndex, bool useTrimBox)
 
PdfRect FillXObjectFromPage (PdfXObject &xobj, const PdfPage &page, bool useTrimBox, unsigned difference)
 
void AttachFile (const PdfFileSpec &fileSpec)
 
PdfFileSpecGetAttachment (const PdfString &name)
 
void AddNamedDestination (const PdfDestination &dest, const PdfString &name)
 
void SetPageMode (PdfPageMode inMode)
 
PdfPageMode GetPageMode () const
 
void SetUseFullScreen ()
 
void SetPageLayout (PdfPageLayout inLayout)
 
void SetHideToolbar ()
 
void SetHideMenubar ()
 
void SetHideWindowUI ()
 
void SetFitWindow ()
 
void SetCenterWindow ()
 
void SetDisplayDocTitle ()
 
void SetPrintScaling (const PdfName &scalingType)
 
void SetBaseURI (const std::string_view &baseURI)
 
void SetLanguage (const std::string_view &language)
 
void SetBindingDirection (const PdfName &direction)
 
virtual bool IsPrintAllowed () const =0
 
virtual bool IsEditAllowed () const =0
 
virtual bool IsCopyAllowed () const =0
 
virtual bool IsEditNotesAllowed () const =0
 
virtual bool IsFillAndSignAllowed () const =0
 
virtual bool IsAccessibilityAllowed () const =0
 
virtual bool IsDocAssemblyAllowed () const =0
 
virtual bool IsHighPrintAllowed () const =0
 
PdfObjectGetCatalog ()
 
const PdfObjectGetCatalog () const
 
PdfPageTreeGetPageTree ()
 
const PdfPageTreeGetPageTree () const
 
PdfObjectGetTrailer ()
 
const PdfObjectGetTrailer () const
 
PdfInfoGetInfo ()
 
const PdfInfoGetInfo () const
 
PdfIndirectObjectListGetObjects ()
 
const PdfIndirectObjectListGetObjects () const
 
PdfObjectGetStructTreeRoot ()
 
PdfObjectGetMetadata ()
 
PdfObjectGetMarkInfo ()
 
PdfObjectGetLanguage ()
 

Protected Member Functions

 PdfDocument (bool empty=false)
 
void SetTrailer (std::unique_ptr< PdfObject > obj)
 
void Init ()
 
void FixObjectReferences (PdfObject &obj, int difference)
 
void SetViewerPreference (const PdfName &whichPref, const PdfObject &valueObj)
 
void SetViewerPreference (const PdfName &whichPref, bool inValue)
 
void Clear ()
 
PdfObjectgetCatalog ()
 

Detailed Description

PdfDocument is the core interface for working with PDF documents.

PdfDocument provides easy access to the individual pages in the PDF file and to certain special dictionaries.

PdfDocument cannot be used directly. Use PdfMemDocument 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
PdfStreamedDocument
PdfMemDocument

Constructor & Destructor Documentation

◆ ~PdfDocument()

PdfDocument::~PdfDocument ( )
virtual

Close down/destruct the PdfDocument

◆ PdfDocument()

PdfDocument::PdfDocument ( bool  empty = false)
protected

Construct a new (empty) PdfDocument

Parameters
emptyif true NO default objects (such as catalog) are created.

Member Function Documentation

◆ AddNamedDestination()

void PdfDocument::AddNamedDestination ( const PdfDestination dest,
const PdfString name 
)

Adds a PdfDestination into the global Names tree with the specified name, optionally replacing one of the same name.

Parameters
destthe destination to be assigned
namethe name for the destination

◆ Append()

const PdfDocument & PdfDocument::Append ( const PdfDocument doc,
bool  appendAll = true 
)

Appends another PdfDocument to this document.

Parameters
docthe document to append
appendAllspecifies whether pages and outlines are appended too
Returns
this document

◆ AttachFile()

void PdfDocument::AttachFile ( const PdfFileSpec fileSpec)

Attach a file to the document.

Parameters
rFileSpeca file specification

◆ Clear()

void PdfDocument::Clear ( )
protected

Clear all internal variables and reset PdfDocument to an intial state.

◆ EmbedSubsetFonts()

void PdfDocument::EmbedSubsetFonts ( )

Embeds all pending subset fonts, is automatically done on Write(). Just call explicitly in case the PdfDocument is needed as PdfXObject.

◆ FillXObjectFromDocumentPage()

PdfRect PdfDocument::FillXObjectFromDocumentPage ( PdfXObject xobj,
const PdfDocument doc,
unsigned  pageIndex,
bool  useTrimBox 
)

Fill an existing empty PdfXObject from a page of another document. This will append the other document to this one.

Parameters
xobjpointer to the PdfXObject
docthe document to embed into the PdfXObject
pageIndexindex of page to embed into the PdfXObject
useTrimBoxif true try to use page's TrimBox for size of PdfXObject
Returns
the bounding box

◆ FillXObjectFromExistingPage()

PdfRect PdfDocument::FillXObjectFromExistingPage ( PdfXObject xobj,
unsigned  pageIndex,
bool  useTrimBox 
)

Fill an existing empty PdfXObject from an existing page from the current document. If you need a page from another document use FillXObjectFromDocumentPage(), or append the document manually.

Parameters
xobjpointer to the PdfXObject
pageIndexindex of page to embed into the PdfXObject
useTrimBoxif true try to use page's TrimBox for size of PdfXObject
Returns
the bounding box

◆ FillXObjectFromPage()

PdfRect PdfDocument::FillXObjectFromPage ( PdfXObject xobj,
const PdfPage page,
bool  useTrimBox,
unsigned  difference 
)

Fill an existing empty PdfXObject from an existing page pointer from the current document. This is the implementation for FillXObjectFromDocumentPage() and FillXObjectFromExistingPage(), you should use those directly instead of this.

Parameters
xobjpointer to the PdfXObject
pagepointer to the page to embed into PdfXObject
useTrimBoxif true try to use page's TrimBox for size of PdfXObject
Returns
the bounding box

◆ FixObjectReferences()

void PdfDocument::FixObjectReferences ( PdfObject obj,
int  difference 
)
protected

Recursively changes every PdfReference in the PdfObject and in any child that is either an PdfArray or a direct object. The reference is changed so that difference is added to the object number of the reference.

Parameters
objobject to change
differenceadd this value to every reference that is encountered

◆ GetAttachment()

PdfFileSpec * PdfDocument::GetAttachment ( const PdfString name)

Get an attached file's filespec.

Parameters
namethe name of the attachment
Returns
the file specification object if the file exists, nullptr otherwise The file specification object is not owned by the document and must be deleted by the caller

◆ GetCatalog() [1/2]

PdfObject & PdfDocument::GetCatalog ( )

Get access to the internal Catalog dictionary or root object.

Returns
PdfObject the documents catalog

◆ getCatalog()

PdfObject * mm::PdfDocument::getCatalog ( )
inlineprotected

Get access to the internal trailer dictionary or root object.

Returns
PdfObject the documents catalog

◆ GetCatalog() [2/2]

const PdfObject & PdfDocument::GetCatalog ( ) const

Get access to the internal Catalog dictionary or root object.

Returns
PdfObject the documents catalog

◆ GetInfo() [1/2]

PdfInfo & PdfDocument::GetInfo ( )

Get access to the internal Info dictionary You can set the author, title etc. of the document using the info dictionary.

Returns
the info dictionary

◆ GetInfo() [2/2]

const PdfInfo & PdfDocument::GetInfo ( ) const

Get access to the internal Info dictionary You can set the author, title etc. of the document using the info dictionary.

Returns
the info dictionary

◆ GetLanguage()

PdfObject * PdfDocument::GetLanguage ( )

Get access to the RFC 3066 natural language id for the document (ISO 32000-1:2008 14.9.2.1)

Returns
PdfObject the language ID string

◆ GetMarkInfo()

PdfObject * PdfDocument::GetMarkInfo ( )

Get access to the MarkInfo dictionary (ISO 32000-1:2008 14.7.1)

Returns
PdfObject the MarkInfo dictionary

◆ GetMetadata()

PdfObject * PdfDocument::GetMetadata ( )

Get access to the Metadata stream

Returns
PdfObject the Metadata stream (should be in XML, using XMP grammar)

◆ GetObjects() [1/2]

PdfIndirectObjectList & mm::PdfDocument::GetObjects ( )
inline

Get access to the internal vector of objects or root object.

Returns
the vector of objects

◆ GetObjects() [2/2]

const PdfIndirectObjectList & mm::PdfDocument::GetObjects ( ) const
inline

Get access to the internal vector of objects or root object.

Returns
the vector of objects

◆ GetOrCreateAcroForm()

PdfAcroForm & PdfDocument::GetOrCreateAcroForm ( PdfAcroFormDefaulAppearance  eDefaultAppearance = PdfAcroFormDefaulAppearance::BlackText12pt)

Get access to the AcroForm dictionary

Parameters
createcreate the object if it does not exist (ePdfCreateObject) or return nullptr if it does not exist
eDefaultAppearancespecifies if a default appearence shall be created
Returns
PdfObject the AcroForm dictionary

◆ GetOrCreateNameTree()

PdfNameTree & PdfDocument::GetOrCreateNameTree ( )

Get access to the Names dictionary (where all the named objects are stored) The returned PdfNameTree object is owned by the PdfDocument.

Parameters
createcreate the object if it does not exist (ePdfCreateObject) or return nullptr if it does not exist
Returns
the Names dictionary

◆ GetOrCreateOutlines()

PdfOutlines & PdfDocument::GetOrCreateOutlines ( )

Get access to the Outlines (Bookmarks) dictionary The returned outlines object is owned by the PdfDocument.

Parameters
createcreate the object if it does not exist (ePdfCreateObject) or return nullptr if it does not exist
Returns
the Outlines/Bookmarks dictionary

◆ GetPageMode()

PdfPageMode PdfDocument::GetPageMode ( ) const

Gets the opening mode for a document.

Returns
which mode is set

◆ GetPageTree() [1/2]

PdfPageTree & PdfDocument::GetPageTree ( )

Get access to the pages tree.

Returns
the PdfPageTree of this document.

◆ GetPageTree() [2/2]

const PdfPageTree & PdfDocument::GetPageTree ( ) const

Get access to the pages tree.

Returns
the PdfPageTree of this document.

◆ GetPdfVersion()

virtual PdfVersion mm::PdfDocument::GetPdfVersion ( ) const
pure virtual

Get the PDF version of the document

Returns
PdfVersion version of the pdf document

Implemented in mm::PdfMemDocument, and mm::PdfStreamedDocument.

◆ GetStructTreeRoot()

PdfObject * PdfDocument::GetStructTreeRoot ( )

Get access to the StructTreeRoot dictionary

Returns
PdfObject the StructTreeRoot dictionary

◆ GetTrailer() [1/2]

PdfObject & PdfDocument::GetTrailer ( )

Get access to the internal trailer dictionary or root object.

Returns
PdfObject the documents catalog

◆ GetTrailer() [2/2]

const PdfObject & PdfDocument::GetTrailer ( ) const

Get access to the internal trailer dictionary or root object.

Returns
PdfObject the documents catalog

◆ Init()

void PdfDocument::Init ( )
protected

Internal method for initializing the pages tree for this document

◆ InsertExistingPageAt()

const PdfDocument & PdfDocument::InsertExistingPageAt ( const PdfDocument doc,
unsigned  pageIndex,
unsigned  atIndex 
)

Inserts existing page from another PdfDocument to this document.

Parameters
docthe document to append from
pageIndexindex of page to append from doc
atIndexindex at which to add the page in this document
Returns
this document

◆ IsAccessibilityAllowed()

virtual bool mm::PdfDocument::IsAccessibilityAllowed ( ) const
pure virtual

Checks if it is allowed to extract text and graphics to support users with disabilities. Every PDF-consuming application has to adhere to this value!

Returns
true if you are allowed to extract text and graphics to support users with disabilities
See also
PdfEncrypt to set own document permissions.

Implemented in mm::PdfMemDocument, and mm::PdfStreamedDocument.

◆ IsCopyAllowed()

virtual bool mm::PdfDocument::IsCopyAllowed ( ) const
pure virtual

Checks if text and graphics extraction is allowed. Every PDF-consuming application has to adhere to this value!

Returns
true if you are allowed to extract text and graphics from this document
See also
PdfEncrypt to set own document permissions.

Implemented in mm::PdfMemDocument, and mm::PdfStreamedDocument.

◆ IsDocAssemblyAllowed()

virtual bool mm::PdfDocument::IsDocAssemblyAllowed ( ) const
pure virtual

Checks if it is allowed to insert, create, rotate, or delete pages or add bookmarks. Every PDF-consuming application has to adhere to this value!

Returns
true if you are allowed to insert, create, rotate, or delete pages or add bookmarks
See also
PdfEncrypt to set own document permissions.

Implemented in mm::PdfMemDocument, and mm::PdfStreamedDocument.

◆ IsEditAllowed()

virtual bool mm::PdfDocument::IsEditAllowed ( ) const
pure virtual

Checks if modifying this document (besides annotations, form fields or substituting pages) is allowed. Every PDF-consuming application has to adhere to this value!

Returns
true if you are allowed to modify this document
See also
PdfEncrypt to set own document permissions.

Implemented in mm::PdfMemDocument, and mm::PdfStreamedDocument.

◆ IsEditNotesAllowed()

virtual bool mm::PdfDocument::IsEditNotesAllowed ( ) const
pure virtual

Checks if it is allowed to add or modify annotations or form fields. Every PDF-consuming application has to adhere to this value!

Returns
true if you are allowed to add or modify annotations or form fields
See also
PdfEncrypt to set own document permissions.

Implemented in mm::PdfMemDocument, and mm::PdfStreamedDocument.

◆ IsFillAndSignAllowed()

virtual bool mm::PdfDocument::IsFillAndSignAllowed ( ) const
pure virtual

Checks if it is allowed to fill in existing form or signature fields. Every PDF-consuming application has to adhere to this value!

Returns
true if you are allowed to fill in existing form or signature fields
See also
PdfEncrypt to set own document permissions.

Implemented in mm::PdfMemDocument, and mm::PdfStreamedDocument.

◆ IsHighPrintAllowed()

virtual bool mm::PdfDocument::IsHighPrintAllowed ( ) const
pure virtual

Checks if it is allowed to print a high quality version of this document Every PDF-consuming application has to adhere to this value!

Returns
true if you are allowed to print a high quality version of this document
See also
PdfEncrypt to set own document permissions.

Implemented in mm::PdfMemDocument, and mm::PdfStreamedDocument.

◆ IsLinearized()

virtual bool mm::PdfDocument::IsLinearized ( ) const
pure virtual

Returns whether this PDF document is linearized, aka web-optimized

Returns
true if the PDF document is linearized

Implemented in mm::PdfMemDocument, and mm::PdfStreamedDocument.

◆ IsPrintAllowed()

virtual bool mm::PdfDocument::IsPrintAllowed ( ) const
pure virtual

Checks if printing this document is allowed. Every PDF-consuming application has to adhere to this value!

Returns
true if you are allowed to print this document
See also
PdfEncrypt to set own document permissions.

Implemented in mm::PdfMemDocument, and mm::PdfStreamedDocument.

◆ SetBaseURI()

void PdfDocument::SetBaseURI ( const std::string_view &  baseURI)

Set the document's Viewer Preferences: Set the base URI of the document.

TODO: DS document value!

◆ SetBindingDirection()

void PdfDocument::SetBindingDirection ( const PdfName direction)

Set the document's Viewer Preferences: Set the document's binding direction.

◆ SetCenterWindow()

void PdfDocument::SetCenterWindow ( )

Set the document's Viewer Preferences: Center the document in the viewer's window.

◆ SetDisplayDocTitle()

void PdfDocument::SetDisplayDocTitle ( )

Set the document's Viewer Preferences: Display the title from the document information in the title of the viewer.

See also
SetTitle

◆ SetFitWindow()

void PdfDocument::SetFitWindow ( )

Set the document's Viewer Preferences: Fit the document in the viewer's window.

◆ SetHideMenubar()

void PdfDocument::SetHideMenubar ( )

Set the document's Viewer Preferences: Hide the menubar in the viewer.

◆ SetHideToolbar()

void PdfDocument::SetHideToolbar ( )

Set the document's Viewer Preferences: Hide the toolbar in the viewer.

◆ SetHideWindowUI()

void PdfDocument::SetHideWindowUI ( )

Set the document's Viewer Preferences: Show only the documents contents and no control elements such as buttons and scrollbars in the viewer.

◆ SetLanguage()

void PdfDocument::SetLanguage ( const std::string_view &  language)

Set the document's Viewer Preferences: Set the language of the document.

◆ SetPageLayout()

void PdfDocument::SetPageLayout ( PdfPageLayout  inLayout)

Sets the page layout for a document.

◆ SetPageMode()

void PdfDocument::SetPageMode ( PdfPageMode  inMode)

Sets the opening mode for a document.

Parameters
inModewhich mode to set

◆ SetPrintScaling()

void PdfDocument::SetPrintScaling ( const PdfName scalingType)

Set the document's Viewer Preferences: Set the default print scaling of the document.

TODO: DS use an enum here!

◆ SetTrailer()

void PdfDocument::SetTrailer ( std::unique_ptr< PdfObject obj)
protected

Set the trailer of this PdfDocument deleting the old one.

Parameters
objthe new trailer object It will be owned by PdfDocument.

◆ SetUseFullScreen()

void PdfDocument::SetUseFullScreen ( )

Sets the opening mode for a document to be in full screen.

◆ SetViewerPreference() [1/2]

void PdfDocument::SetViewerPreference ( const PdfName whichPref,
bool  inValue 
)
protected

Low-level APIs for setting a viewer preference. Convenience overload.

Parameters
whichPrefthe dictionary key to set
inValuethe object to be set

◆ SetViewerPreference() [2/2]

void PdfDocument::SetViewerPreference ( const PdfName whichPref,
const PdfObject valueObj 
)
protected

Low-level APIs for setting a viewer preference.

Parameters
whichPrefthe dictionary key to set
valueObjthe object to be set