Poppler CPP 24.04.0
Public Types | Public Member Functions | Static Public Member Functions | List of all members
poppler::document Class Reference

#include "poppler/cpp/poppler-document.h"

Inheritance diagram for poppler::document:
Inheritance graph
[legend]

Public Types

enum  page_layout_enum {
  no_layout ,
  single_page ,
  one_column ,
  two_column_left ,
  two_column_right ,
  two_page_left ,
  two_page_right
}
 
enum  page_mode_enum {
  use_none ,
  use_outlines ,
  use_thumbs ,
  fullscreen ,
  use_oc ,
  use_attach
}
 

Public Member Functions

std::map< std::string, destinationcreate_destination_map () const
 
font_iteratorcreate_font_iterator (int start_page=0) const
 
pagecreate_page (const ustring &label) const
 
pagecreate_page (int index) const
 
toccreate_toc () const
 
std::vector< embedded_file * > embedded_files () const
 
std::vector< font_infofonts () const
 
ustring get_author () const
 
time_type get_creation_date () const
 
time_t get_creation_date_t () const
 
ustring get_creator () const
 
ustring get_keywords () const
 
time_type get_modification_date () const
 
time_t get_modification_date_t () const
 
bool get_pdf_id (std::string *permanent_id, std::string *update_id) const
 
void get_pdf_version (int *major, int *minor) const
 
ustring get_producer () const
 
ustring get_subject () const
 
ustring get_title () const
 
bool has_embedded_files () const
 
bool has_permission (permission_enum which) const
 
time_type info_date (const std::string &key) const
 
time_t info_date_t (const std::string &key) const
 
ustring info_key (const std::string &key) const
 
std::vector< std::string > info_keys () const
 
bool is_encrypted () const
 
bool is_linearized () const
 
bool is_locked () const
 
ustring metadata () const
 
page_layout_enum page_layout () const
 
page_mode_enum page_mode () const
 
int pages () const
 
bool remove_info ()
 
bool save (const std::string &file_name) const
 
bool save_a_copy (const std::string &file_name) const
 
bool set_author (const ustring &author)
 
bool set_creation_date (time_type creation_date)
 
bool set_creation_date_t (time_t creation_date)
 
bool set_creator (const ustring &creator)
 
bool set_info_date (const std::string &key, time_type val)
 
bool set_info_date_t (const std::string &key, time_t val)
 
bool set_info_key (const std::string &key, const ustring &val)
 
bool set_keywords (const ustring &keywords)
 
bool set_modification_date (time_type mod_date)
 
bool set_modification_date_t (time_t mod_date)
 
bool set_producer (const ustring &producer)
 
bool set_subject (const ustring &subject)
 
bool set_title (const ustring &title)
 
bool unlock (const std::string &owner_password, const std::string &user_password)
 

Static Public Member Functions

static documentload_from_data (byte_array *file_data, const std::string &owner_password=std::string(), const std::string &user_password=std::string())
 
static documentload_from_file (const std::string &file_name, const std::string &owner_password=std::string(), const std::string &user_password=std::string())
 
static documentload_from_raw_data (const char *file_data, int file_data_length, const std::string &owner_password=std::string(), const std::string &user_password=std::string())
 

Detailed Description

Represents a PDF document.

Member Enumeration Documentation

◆ page_mode_enum

The various page modes available in a PDF document.

Enumerator
use_none 

The document specifies no particular page mode.

use_outlines 

The document specifies its TOC (table of contents) should be open.

use_thumbs 

The document specifies that should be open a view of the thumbnails of its pages.

fullscreen 

The document specifies it wants to be open in a fullscreen mode.

use_oc 

The document specifies that should be open a view of its Optional Content (also known as layers).

use_attach 

The document specifies that should be open a view of its document-level attachments.

Member Function Documentation

◆ create_destination_map()

std::map< std::string, destination > document::create_destination_map ( ) const

Creates a map of all the named destinations in the document.

Note
The destination names may contain \0 and other binary values so they are not printable and cannot convert to null-terminated C strings.
Returns
the map of the each name and destination
Since
0.74

◆ create_font_iterator()

font_iterator * document::create_font_iterator ( int  start_page = 0) const

Creates a new font iterator.

This creates a new font iterator for reading the font information of the document page by page, starting at the specified start_page (0 if not specified).

Returns
a new font iterator

◆ create_page() [1/2]

page * document::create_page ( const ustring label) const

Document page by label reading.

This creates a new page representing the document page whose label is the specified label. If there is no page with that label, NULL is returned.

Returns
a new page object or NULL

◆ create_page() [2/2]

page * document::create_page ( int  index) const

Document page by index reading.

This creates a new page representing the index -th page of the document.

Note
the page indexes are in the range [0, pages()[.
Returns
a new page object or NULL

◆ create_toc()

toc * document::create_toc ( ) const

Reads the TOC (table of contents) of the document.

Returns
a new toc object if a TOC is available, NULL otherwise

◆ embedded_files()

std::vector< embedded_file * > document::embedded_files ( ) const

Reads all the document-level embedded files of the document.

Returns
the document-level embedded files

◆ fonts()

std::vector< font_info > document::fonts ( ) const

Reads all the font information of the document.

Note
this can be slow for big documents; prefer the use of a font_iterator to read incrementally page by page
See also
create_font_iterator

◆ get_author()

ustring document::get_author ( ) const

Gets the document's author.

Returns
the document's author, or an empty string if not available
See also
set_author, info_key

◆ get_creation_date()

time_type document::get_creation_date ( ) const

Gets the document's creation date as a time_type value.

Returns
the document's creation date as a time_type value
See also
set_creation_date, info_date

◆ get_creation_date_t()

time_t document::get_creation_date_t ( ) const

Gets the document's creation date as a time_t value.

Returns
the document's creation date as a time_t value
See also
set_creation_date, info_date

◆ get_creator()

ustring document::get_creator ( ) const

Gets the document's creator.

Returns
the document's creator, or an empty string if not available
See also
set_creator, info_key

◆ get_keywords()

ustring document::get_keywords ( ) const

Gets the document's keywords.

Returns
the document's keywords, or an empty string if not available
See also
set_keywords, info_key

◆ get_modification_date()

time_type document::get_modification_date ( ) const

Gets the document's modification date as a time_type value.

Returns
the document's modification date as a time_type value
See also
set_modification_date, info_date

◆ get_modification_date_t()

time_t document::get_modification_date_t ( ) const

Gets the document's modification date as a time_t value.

Returns
the document's modification date as a time_t value
See also
set_modification_date, info_date

◆ get_pdf_id()

bool document::get_pdf_id ( std::string *  permanent_id,
std::string *  update_id 
) const

Gets the IDs of the current PDF document, if available.

Parameters
permanent_idif not NULL, will be set to the permanent ID of the document
update_idif not NULL, will be set to the update ID of the document
Returns
whether the document has the IDs
Since
0.16

◆ get_pdf_version()

void document::get_pdf_version ( int *  major,
int *  minor 
) const

Gets the version of the current PDF document.

Example:

poppler::document *doc = ...;
// for example, if the document is PDF 1.6:
int major = 0, minor = 0;
doc->get_pdf_version(&major, &minor);
// major == 1
// minor == 6
Represents a PDF document.
Definition poppler-document.h:39
void get_pdf_version(int *major, int *minor) const
Gets the version of the current PDF document.
Definition poppler-document.cpp:251
Parameters
majorif not NULL, will be set to the "major" number of the version
minorif not NULL, will be set to the "minor" number of the version

◆ get_producer()

ustring document::get_producer ( ) const

Gets the document's producer.

Returns
the document's producer, or an empty string if not available
See also
set_producer, info_key

◆ get_subject()

ustring document::get_subject ( ) const

Gets the document's subject.

Returns
the document's subject, or an empty string if not available
See also
set_subject, info_key

◆ get_title()

ustring document::get_title ( ) const

Gets the document's title.

Returns
the document's title, or an empty string if not available
See also
set_title, info_key

◆ has_embedded_files()

bool document::has_embedded_files ( ) const

Reads whether the current document has document-level embedded files (attachments).

This is a very fast way to know whether there are embedded files (also known as "attachments") at the document-level. Note this does not take into account files embedded in other ways (e.g. to annotations).

Returns
whether the document has embedded files

◆ has_permission()

bool document::has_permission ( permission_enum  which) const

Check for available "document permission".

Returns
whether the specified permission is allowed

◆ info_date()

time_type document::info_date ( const std::string &  key) const

Gets the time_type value of the specified key of the document information.

Returns
the time_t value for the key
See also
info_keys, info_date

◆ info_date_t()

time_t document::info_date_t ( const std::string &  key) const

Gets the time_t value of the specified key of the document information.

Returns
the time_t value for the key
See also
info_keys, info_date

◆ info_key()

ustring document::info_key ( const std::string &  key) const

Gets the value of the specified key of the document information.

Returns
the value for the key, or an empty string if not available
See also
info_keys, info_date

◆ info_keys()

std::vector< std::string > document::info_keys ( ) const
Returns
all the information keys available in the document
See also
info_key, info_date

◆ is_encrypted()

bool document::is_encrypted ( ) const
Returns
whether the document is encrypted

◆ is_linearized()

bool document::is_linearized ( ) const
Returns
whether the document is linearized

◆ is_locked()

bool document::is_locked ( ) const
Returns
whether the current document is locked

◆ load_from_data()

document * document::load_from_data ( byte_array *  file_data,
const std::string &  owner_password = std::string(),
const std::string &  user_password = std::string() 
)
static

Tries to load a PDF document from the specified data.

Note
if the loading succeeds, the document takes ownership of the file_data (swap()ing it)
Parameters
file_datathe data representing a document to open
Returns
a new document if the load succeeded (even if the document is locked), NULL otherwise

◆ load_from_file()

document * document::load_from_file ( const std::string &  file_name,
const std::string &  owner_password = std::string(),
const std::string &  user_password = std::string() 
)
static

Tries to load a PDF document from the specified file.

Parameters
file_namethe file to open
Returns
a new document if the load succeeded (even if the document is locked), NULL otherwise

◆ load_from_raw_data()

document * document::load_from_raw_data ( const char *  file_data,
int  file_data_length,
const std::string &  owner_password = std::string(),
const std::string &  user_password = std::string() 
)
static

Tries to load a PDF document from the specified data buffer.

Note
the buffer must remain valid for the whole lifetime of the returned document
Parameters
file_datathe data buffer representing a document to open
file_data_lengththe length of the data buffer
Returns
a new document if the load succeeded (even if the document is locked), NULL otherwise
Since
0.16

◆ metadata()

ustring document::metadata ( ) const

Reads the document metadata string.

Returns
the document metadata string

◆ page_layout()

document::page_layout_enum document::page_layout ( ) const
Returns
the eventual page layout specified by the current PDF document

◆ page_mode()

document::page_mode_enum document::page_mode ( ) const
Returns
the eventual page mode specified by the current PDF document

◆ pages()

int document::pages ( ) const

Document page count.

Returns
the number of pages of the document

◆ remove_info()

bool document::remove_info ( )

Removes the document's Info dictionary.

Returns
true on success, false on failure

◆ save()

bool document::save ( const std::string &  file_name) const

Saves the document to file file_name.

Returns
true on success, false on failure

◆ save_a_copy()

bool document::save_a_copy ( const std::string &  file_name) const

Saves the original version of the document to file file_name.

Returns
true on success, false on failure

◆ set_author()

bool document::set_author ( const ustring author)

Sets the document's author to author.

If author is empty, the document's author is removed.

Returns
true on success, false on failure

◆ set_creation_date()

bool document::set_creation_date ( time_type  creation_date)

Sets the document's creation date to creation_date.

If creation_date == time_type(-1), the document's creation date is removed.

Returns
true on success, false on failure

◆ set_creation_date_t()

bool document::set_creation_date_t ( time_t  creation_date)

Sets the document's creation date to creation_date.

If creation_date == time_t(-1), the document's creation date is removed.

Returns
true on success, false on failure

◆ set_creator()

bool document::set_creator ( const ustring creator)

Sets the document's creator to creator.

If creator is empty, the document's creator is removed.

Returns
true on success, false on failure

◆ set_info_date()

bool document::set_info_date ( const std::string &  key,
time_type  val 
)

Sets the time_type value of the specified key of the document information to val.

If val == time_type(-1), the entry specified by key is removed.

Returns
true on success, false on failure

◆ set_info_date_t()

bool document::set_info_date_t ( const std::string &  key,
time_t  val 
)

Sets the time_t value of the specified key of the document information to val.

If val == time_t(-1), the entry specified by key is removed.

Returns
true on success, false on failure

◆ set_info_key()

bool document::set_info_key ( const std::string &  key,
const ustring val 
)

Sets the value of the specified key of the document information to val.

If val is empty, the entry specified by key is removed.

Returns
true on success, false on failure

◆ set_keywords()

bool document::set_keywords ( const ustring keywords)

Sets the document's keywords to keywords.

If keywords is empty, the document's keywords are removed.

Returns
true on success, false on failure

◆ set_modification_date()

bool document::set_modification_date ( time_type  mod_date)

Sets the document's modification date to mod_date.

If mod_date == time_type(-1), the document's modification date is removed.

Returns
true on success, false on failure

◆ set_modification_date_t()

bool document::set_modification_date_t ( time_t  mod_date)

Sets the document's modification date to mod_date.

If mod_date == time_t(-1), the document's modification date is removed.

Returns
true on success, false on failure

◆ set_producer()

bool document::set_producer ( const ustring producer)

Sets the document's producer to producer.

If producer is empty, the document's producer is removed.

Returns
true on success, false on failure

◆ set_subject()

bool document::set_subject ( const ustring subject)

Sets the document's subject to subject.

If subject is empty, the document's subject is removed.

Returns
true on success, false on failure

◆ set_title()

bool document::set_title ( const ustring title)

Sets the document's title to title.

If title is empty, the document's title is removed.

Returns
true on success, false on failure

◆ unlock()

bool document::unlock ( const std::string &  owner_password,
const std::string &  user_password 
)

Unlocks the current document, if locked.

Returns
the new locking status of the document