Document Class Documentation
classDocumentNamespace:datalogics_interface
Detailed Description
Use document objects to perform most of the functions related to pages in a PDF file, such as deleting pages, inserting blank pages, copying watermarks, creating bookmarks and thumbnails, and so on.
Threading: single-thread use. A Document is bound to the Library active on the thread where it was constructed. Do not share Document instances across threads. See datalogics_interface.hpp for the full threading model.
Referenced by
Constructor & Destructor Documentation
Document
Document()Creates a new document. The only Cos object in the document will be a Catalog. After the document is created, at least one page must be added using CreatePage or InsertPages before the PDF Viewer can display or save the document.
Document
Document(const std::string &file_name)Parameters
file_name: const std::string &
Creates a new document. The only Cos object in the document will be a Catalog. After the document is created, at least one page must be added using CreatePage or InsertPages before the PDF Viewer can display or save the document.
Document
Document(const std::string &file_name, const std::string &password, booldo_repair)Parameters
file_name: const std::string &password: const std::string &do_repair: bool
Creates a new document. The only Cos object in the document will be a Catalog. After the document is created, at least one page must be added using CreatePage or InsertPages before the PDF Viewer can display or save the document.
Document
Document(const std::string &xps_file, XPSConvertParams ¶ms)Parameters
xps_file: const std::string ¶ms: XPSConvertParams &
Creates a new document. The only Cos object in the document will be a Catalog. After the document is created, at least one page must be added using CreatePage or InsertPages before the PDF Viewer can display or save the document.
Document
Document(Document &&)Parameters
Document
Document(std::istream &input_stream)Parameters
input_stream: std::istream &
Open a document from an input stream. The stream must remain valid for the lifetime of the Document.
Document
Document(std::istream &input_stream, const std::string &password, booldo_repair)Parameters
input_stream: std::istream &password: const std::string &do_repair: bool
Open a password-protected document from an input stream.
~Document
~Document()Closes that document and releases its resources. Changes are not saved. You must use Save() to save any modifications before destroying this object.
Member Function Documentation
apply_redactions
boolapply_redactions()Returns:
boolApply redactions to the document.
apply_redactions
boolapply_redactions(Redaction &redaction)Parameters
redaction: Redaction &the redaction to apply, or NULL to apply all redactions in the document.
Returns:
boolApply redactions to the document.
clone_as_pdfa_document
ConvertResultclone_as_pdfa_document(PDFAConvertTypetype, const PDFAConvertParams ¶ms)Parameters
type: PDFAConvertTypeThe type of PDF/A conversion to perform
params: const PDFAConvertParams &A PDFAConvertParams object specifying options for the conversion
Returns:
A PDFAConvertResult object containing the Document and SaveFlags.Create a PDF/A compliant version of this Document.
The returned Document will be compliant with the PDF/A standard. You can save it using any of the standard Save() methods.
The PDFAConvertResult object contains both the Document and the SaveFlags you should use when saving the Document. You MUST use these exact flags to save the returned Document or it will no longer be PDF/A compliant.
The returned Document will have its MajorVersion and MinorVersion set to "1" and "4" respectively. This is required for PDF/A compliance.
If this Document could not be converted to PDF/A, the PDFADocument field in the PDFAConvertResult object will be null.
clone_as_pdfx_document
ConvertResultclone_as_pdfx_document(PDFXConvertTypetype, const PDFXConvertParams ¶ms)Parameters
type: PDFXConvertTypeThe type of PDF/X conversion to perform
params: const PDFXConvertParams &A PDFXConvertParams object specifying options for the conversion
Returns:
A PDFXConvertResult object containing the Document and SaveFlags.Create a PDF/X compliant version of this Document.
The returned Document will be compliant with the PDF/X standard. You can save it using any of the standard Save() methods.
The PDFXConvertResult object contains both the Document and the SaveFlags you should use when saving the Document. You MUST use these exact flags to save the returned Document or it will no longer be PDF/X compliant.
The returned Document will have its MajorVersion and MinorVersion set to "1" and "4" respectively. This is required for PDF/X compliance.
If this Document could not be converted to PDF/X, the PDFXDocument field in the PDFXConvertResult object will be null.
close
voidclose()Returns:
voidCloses a document and releases its resources. Changes are not saved. You must use Save to save any modifications before calling Close.
color_convert_pages
boolcolor_convert_pages(const ColorConvertParams ¶ms)Parameters
params: const ColorConvertParams &the color conversion parameters specifying the ICC profile to apply.
Returns:
True if color conversion occurred. False if nothing was color converted.Convert the colors (in place) in a Document as specified by by the params block by applying an ICC profile to the objects contained in the Document.
convert_to_excel
static boolconvert_to_excel(const std::string &input_path, const std::string &output_path)Parameters
input_path: const std::string &The PDF file path to convert.
output_path: const std::string &The output Office file path.
Returns:
true if the conversion was successful, false if an error occurred.This function converts a PDF file to a Microsoft Excel Office file (.xlsx).
NOTE: This method is only available on Windows 32/64-bit and Linux 64-bit.
Only available on Windows. Throws std::runtime_error on other platforms.
convert_to_powerpoint
static boolconvert_to_powerpoint(const std::string &input_path, const std::string &output_path)Parameters
input_path: const std::string &The PDF file path to convert.
output_path: const std::string &The output Office file path.
Returns:
true if the conversion was successful, false if an error occurred.This function converts a PDF file to a Microsoft PowerPoint Office file (.pptx).
NOTE: This method is only available on Windows 32/64-bit and Linux 64-bit.
Only available on Windows. Throws std::runtime_error on other platforms.
convert_to_word
static boolconvert_to_word(const std::string &input_path, const std::string &output_path)Parameters
input_path: const std::string &The PDF file path to convert.
output_path: const std::string &The output Office file path.
Returns:
true if the conversion was successful, false if an error occurred.This function converts a PDF file to a Microsoft Word Office file (.docx).
NOTE: This method is only available on Windows 32/64-bit and Linux 64-bit.
Only available on Windows. Throws std::runtime_error on other platforms.
convert_xfa_to_acroform
intconvert_xfa_to_acroform()Returns:
the number of output pages created in the converted documentXFA content is not widely supported by PDF processors, converting this content transforms XFA fields into AcroForm fields which are more widely suppored by PDF processors All XFA fields are removed.
NOTE: This method is part of the APDFL Forms Extension that is available separately from APDFL. For more information, please see https://www.datalogics.com/pdf-form-functions.
count_xmp_metadata_array_items
intcount_xmp_metadata_array_items(const std::string &ns, const std::string &path)Parameters
ns: const std::string &The XML namespace URI for the schema in which the property is to be found.
path: const std::string &The name of the simple property .
Returns:
number of array items in the property array.Returns the number of array items in a property array associated with a Document.
create_collection
voidcreate_collection()Returns:
voidCreateCollection allows to create new collection in the PDF document. It replaces any existing collection.
create_name_tree
std::unique_ptr< NameTree >create_name_tree(const std::string &name)Parameters
name: const std::string &The name of the NameTree to create.
Returns:
The retrieved or newly created NameTree.Retrieves the name tree inside the Names dictionary with the specified key name, or creates it if it does not exist.
create_page
Pagecreate_page(intafter_page_num, const Rect &media_box)Parameters
after_page_num: intThe page number after which the new page is inserted. The first page is 0. Use Document.BeforeFirstPage to insert the new page at the beginning of a document.
media_box: const Rect &A rectangle specifying the page's media box, specified in user space coordinates.
Returns:
The newly created page.Creates and acquires a new Page. The page is inserted into the document at the specified location.
create_struct_tree_root
StructTreeRootcreate_struct_tree_root()Returns:
StructTreeRootCreates a StructTreeRoot in the catalog; throws std::logic_error if one already exists. Also sets /MarkInfo {/Marked true} in the catalog.
delete_pages
voiddelete_pages(intfirst_page, intlast_page)Parameters
first_page: intThe page number of the first page to delete. The first page is 0.
last_page: intThe page number of the last page to delete.
Returns:
voidDeletes the specified pages.
embed_fonts
voidembed_fonts()Returns:
voidEmbed unembedded fonts in a document.
To keep the changes the document must be saved. Fonts on the user's system that match the original font definition will be embedded. For the Times-Roman and Helvetica and corresponding styles, if displayed with a font alias, then the font alias will be embedded in the file. If the font has information that indicates the font cannot be embedded for print and preview, then the font will not be embedded in the document.
With no flags, fonts marked as embedded or subsettable will be embedded.
By default, the font embedding process scans the entire document for font usage information when subsetting fonts. For documents with large numbers of fonts or pages, this can take a long time. In cases where new Font objects are created and used to set text, it's not necessary to scan the entire document; instead, use the version of this call that takes a list of Font objects and a set of flags for embedding. Passing the list of new Fonts and the DontScanDocument flag will directly embed the fonts in the list without scanning the document.
embed_ocr_fonts
voidembed_ocr_fonts()Returns:
voidEmbed fonts that were used in creating OCR text.
This is also done automatically when saving.
export_acro_forms_data
boolexport_acro_forms_data(const std::string &path, AcroFormExportTypetype)Parameters
path: const std::string &The path on disk of the file the AcroForms data is exported to.
type: AcroFormExportTypeThe format type the AcroForm data should be exported to. The supported types are XFDF, FDF, and XML.
Returns:
true indicates exporting succeeded and false indicates an error occurredAcroForms data is exported into a format that can later be imported into another AcroForms document.
NOTE: This method is part of the APDFL Forms Extension that is available separately from APDFL. For more information, please see https://www.datalogics.com/pdf-form-functions.
export_as_postscript
voidexport_as_postscript(PrintUserParams ¶ms, const std::string &path)Parameters
params: PrintUserParams &Parameters to control printing.
path: const std::string &The output file to be created.
Returns:
voidExports a PDF document or pages from a PDF document as PostScript allowing the caller to specify options such as page size, rotation, and shrink-to-fit.
The output is placed in the specified file.
export_xfa_forms_data
boolexport_xfa_forms_data(const std::string &path, XFAFormExportTypetype)Parameters
path: const std::string &The path on disk of the file the XFA form data is exported to.
type: XFAFormExportTypeThe format type the XFA data should be exported to. The supported types are XDP, XML, and XFD.
Returns:
true indicates exporting succeeded and false indicates an error occurredXFA forms data is exported into a format that can later be imported into another XFA document.
NOTE: This method is part of the APDFL Forms Extension that is available separately from APDFL. For more information, please see https://www.datalogics.com/pdf-form-functions.
find_bookmark
std::unique_ptr< Bookmark >find_bookmark(const std::string &title)Parameters
title: const std::string &- The title of the bookmark for which to search.
Returns:
The bookmark within the document's bookmark tree that has the supplied title. Returns NULL if there is no bookmark with the supplied title.Find bookmark by its title, searching within the document's bookmark tree to a depth determined by maxDepth (e.g., 0 = root bookmark only and not any of its children, 1 = search one level below root bookmark level, etc. Omit to search entire bookmark tree.)
find_bookmark
std::unique_ptr< Bookmark >find_bookmark(const std::string &title, intmax_depth)Parameters
title: const std::string &- The title of the bookmark for which to search.
max_depth: int- If supplied (with a value greater than or equal to 0), declares the number of levels below this bookmark to search. (If omitted, the entire subtree is searched.)
Returns:
The bookmark within the document's bookmark tree that has the supplied title. Returns NULL if there is no bookmark with the supplied title.Find bookmark by its title, searching within the document's bookmark tree to a depth determined by maxDepth (e.g., 0 = root bookmark only and not any of its children, 1 = search one level below root bookmark level, etc. Omit to search entire bookmark tree.)
find_label_for_page_num
std::stringfind_label_for_page_num(intpage_index)Parameters
page_index: intIndex of a page in the Document
Returns:
The label string for the pageFetch the label string for a page index, using the current page labels.
find_page_num_for_label
intfind_page_num_for_label(const std::string &label)Parameters
label: const std::string &The label string to look up
Returns:
The index of the corresponding page, or -1 if the label could not be matchedLook up a page index based on a label string.
find_pdf_object_by_id
std::unique_ptr< PDFObject >find_pdf_object_by_id(intid)Parameters
id: intThe object ID number to look up.
Returns:
The PDFObject with the specified ID, or null if no such object exists.Note that direct PDFObjects cannot be retrieved by ID.
flatten_acro_form_fields
voidflatten_acro_form_fields()Returns:
voidInteractive AcroForm fields are flattened into static PDF page content. All AcroForm fields are removed.
NOTE: This method is part of the APDFL Forms Extension that is available separately from APDFL. For more information, please see https://www.datalogics.com/pdf-form-functions.
flatten_transparency
intflatten_transparency()Returns:
The number of pages that were flattened.Flattens all transparencies in the document. To flatten specific pages, see Document.FlattenTransparency(params, firstPage, lastPage)
Documents are flattened one at a time. In multi-threaded applications, threads that are making simultaneous calls to this method will block and execute the method sequentially.
flatten_transparency
intflatten_transparency(const FlattenTransparencyParams ¶ms)Parameters
Returns:
The number of pages that were flattened.Flattens all transparencies in the document. To flatten specific pages, see Document.FlattenTransparency(params, firstPage, lastPage)
Documents are flattened one at a time. In multi-threaded applications, threads that are making simultaneous calls to this method will block and execute the method sequentially.
flatten_transparency
intflatten_transparency(const FlattenTransparencyParams ¶ms, intfirst_page, intlast_page)Parameters
first_page: intlast_page: int
Returns:
The number of pages that were flattened.Flattens all transparencies in the document. To flatten specific pages, see Document.FlattenTransparency(params, firstPage, lastPage)
Documents are flattened one at a time. In multi-threaded applications, threads that are making simultaneous calls to this method will block and execute the method sequentially.
flatten_xfa_form_fields
intflatten_xfa_form_fields()Returns:
the number of output pages created in the flattened document.XFA content is not widely supported by PDF processors, flattening this content transforms into static PDF page content that is part of typical PDF files that can easily be understood by PDF processors. All XFA fields are removed.
NOTE: This method is part of the APDFL Forms Extension that is available separately from APDFL. For more information, please see https://www.datalogics.com/pdf-form-functions.
for_each_indirect_object
voidfor_each_indirect_object(const std::function< bool(PDFObject &)> &callback)Parameters
callback: const std::function< bool(PDFObject &)> &A user-supplied callback to call for each indirect object in dP. Enumeration ends when enumProc returns false or all indirect objects have been enumerated. The value parameter returned in enumProc is always null.
Returns:
true if all of the calls to enumProc returned true. It returns false as soon as a call to enumProc returns false.Enumerate every indirect PDF object in this document. The callback receives a reference to each indirect object in turn and should return true to continue or false to stop enumeration. Order is undefined and may differ between calls. Enumerates all the indirect objects of this document.
The objects are enumerated in no particular order. Successive enumerations of the same Document are not guaranteed to enumerate objects in the same order.
This method does not enumerate invalid objects, which include objects that are defined as null, objects that are not defined at all (those having no cross-reference entry), and objects that are on the free list.
This re-raises any exception that proc raises.
get_attachments
std::vector< std::shared_ptr< FileAttachment > >get_attachments()Returns:
The list of attached files.Gets all attached files from the PDF document.
get_author
std::stringget_author()Returns:
std::stringThe author of the PDF document.
get_base_uri
std::stringget_base_uri()Returns:
std::stringThe Base URI of the PDF document.
get_bookmark_root
std::unique_ptr< Bookmark >get_bookmark_root()Returns:
The document's root bookmark.The return value is valid even if the document's bookmark tree is empty (meaning that there is no Outlines key in the underlying PDF file).
get_collection
std::unique_ptr< Collection >get_collection()Returns:
collection object if collection exists in the Document or NULL otherwise.GetCollection allows to retrieve collection from the PDF document.
get_compression_level
intget_compression_level()Returns:
intThe compression level can be one of three values returned by this property:
0 - No compression. All objects are available without inflation. 1 - Partial compression. Objects related to logical structure are stored in object streams and must be inflated. 2 - Full compression. All objects are compressed and must be inflated.
get_creator
std::stringget_creator()Returns:
std::stringThe creator of the PDF file.
get_delete_on_close
boolget_delete_on_close()Returns:
The DeleteOnClose property.The document is based on a temporary file that must be deleted when the document is closed or saved.
get_file_name
std::stringget_file_name()Returns:
The filename associated with this Document.Get the filename associated with this Document, if it has a representation on disk.
get_fonts
std::vector< Font >get_fonts(intfirst_page, intlast_page)Parameters
first_page: intThe page number of the first page for which fonts are enumerated. The first page is 0.
last_page: intThe page number of the last page for which fonts are enumerated.
Returns:
A list of Font objects found in the specified page range.This may take a considerable amount of time for a large page range.
get_has_signature
boolget_has_signature()Returns:
If the Document has a Digital Signature.The document contains a Digital Signature.
get_info
std::stringget_info(const std::string &key)Parameters
key: const std::string &The name of metadata which value will be obtained.
Returns:
The value of the metadata obtained from the PDF file.Gets the value of metadata information in a PDF file.
get_info_dict
std::unique_ptr< PDFDict >get_info_dict()Returns:
std::unique_ptr< PDFDict >The Info dictionary of the document as a PDFObject.
get_instance_id
std::vector< unsigned char >get_instance_id()Returns:
std::vector< unsigned char >Get the instance ID for this document.
get_is_linearized
boolget_is_linearized()Returns:
The IsLinearized propertyThe document is linearized (optimized) for page-served remote (network) access. This flag is get only.
get_is_modified
boolget_is_modified()Returns:
The IsModified property.This flag is get only.
get_is_optimized
boolget_is_optimized()Returns:
The IsOptimized propertyThe document is optimized. If this flag is cleared, the Adobe PDF Library does not save the file optimized. You can, therefore, linearize a PDF file without optimizing it. Optimizing without linearizing is not allowed, however. This flag can only be set, never cleared.
get_keywords
std::stringget_keywords()Returns:
std::stringThe keywords of the PDF file.
get_loaded_fonts
std::vector< Font >get_loaded_fonts()Returns:
std::vector< Font >Enumerates all the fonts that have been encountered so far. A font is loaded when a page that uses it is processed. This typically happens when a page is drawn or its thumbnail image is created.
get_major_version
intget_major_version()Returns:
The major PDF version number of the document.The major PDF version number of the document. The PDF version is specified in the header of a PDF file in the string "%PDF-xx. yy" where xx is the major version and yy is the minor version.
get_minor_version
intget_minor_version()Returns:
The minor PDF version number of the document.The minor PDF version number of the document. The PDF version is specified in the header of a PDF file in the string "%PDF-xx. yy" where xx is the major version and yy is the minor version.
Please note: Setting the minor version on a document only changes the version number in the document's file header. It will NOT actually change the PDF's contents and it will NOT alter the PDF to conform to the standard of the new minor version.
The new minor version number will appear in the file header once the document is saved.
get_name_tree
std::unique_ptr< NameTree >get_name_tree(const std::string &name)Parameters
name: const std::string &The name of the NameTree to get.
Returns:
The retrieved NameTree.Retrieves the name tree inside the Names dictionary with the specified key name.
get_needs_save
boolget_needs_save()Returns:
The NeedsSave property.The document has been modified and needs to be saved.
get_num_pages
intget_num_pages()Returns:
The number of pages in the document. Remember to subtract 1 from this value if you are going to pass it to a Page method that takes a zero-based page number.Gets the number of pages in a document.
get_optional_content_groups
std::vector< OptionalContentGroup >get_optional_content_groups()Returns:
A list of COptionalContentGroup objects.The order of the groups is not guaranteed to be the creation order, and is not the same as the display order (see PDOCConfigGetOCGOrder()).
get_page
Pageget_page(intpage_number)Parameters
page_number: intThe page number of the page to acquire. The first page is 0.
Returns:
The requested Page object.Gets a Page from a document.
get_page_labels
std::vector< PageLabel >get_page_labels()Returns:
std::vector< PageLabel >PageLabels are always stored in page index order; if two PageLabels start on the same page index, the last PageLabel appearing in the list will be used.
get_page_mode
PageModeget_page_mode()Returns:
PageModeThe PageMode of the PDF document.
get_permanent_id
std::vector< unsigned char >get_permanent_id()Returns:
std::vector< unsigned char >Get the permanent ID for this document.
get_permission_flags
PermissionFlagsget_permission_flags()Returns:
flags that have been setAllows to obtain security flags for the document.
get_producer
std::stringget_producer()Returns:
std::stringThe producer of the PDF file.
get_requires_full_save
boolget_requires_full_save()Returns:
The RequiresFullSave property.This flag can only be set, never cleared.
get_root
std::unique_ptr< PDFDict >get_root()Returns:
std::unique_ptr< PDFDict >The Catalog of the document as a PDFObject.
get_struct_tree_root
std::optional< StructTreeRoot >get_struct_tree_root()Returns:
std::optional< StructTreeRoot >Returns the StructTreeRoot if present, nullptr otherwise.
get_subject
std::stringget_subject()Returns:
std::stringThe subject of the PDF document.
get_suppress_errors
boolget_suppress_errors()Returns:
The SuppressErrors propertyDo not display errors.
get_title
std::stringget_title()Returns:
std::stringThe title of the PDF document.
get_version_string
std::stringget_version_string()Returns:
A string containing the PDF version number of the document.The PDF version of the document, which is specified in the header of a PDF file in the string "%PDF-xx.yy" where xx is the major version and yy is the minor version.
Note that this returns a string containing both the major and minor versions. For version comparisons, use MajorVersion and MinorVersion.
get_was_repaired
boolget_was_repaired()Returns:
The WasRepaired property.This flag is get only.
get_xmp_metadata
std::stringget_xmp_metadata()Returns:
std::stringThe XMP metadata returned always represents all the properties in the Document's Info dictionary, and can also contain properties not present in the Info dictionary. This call is preferred to GetInfo, which only returns properties that are in the Info dictionary (although the older function is supported for compatibility).
get_xmp_metadata_array_item
std::stringget_xmp_metadata_array_item(const std::string &ns, const std::string &path, intindex)Parameters
ns: const std::string &The XML namespace URI for the schema in which the property is to be found.
path: const std::string &The name of the desired simple property.
index: intThe index in the metadata property array associated with the property.
Returns:
a string containing the XML text of the value of the specified property in the XMP metadata associated with the Document, or an empty string if no such property is found.Gets the value of an XMP metadata array item, associated with a document, based on an index.
get_xmp_metadata_property
std::stringget_xmp_metadata_property(const std::string &ns, const std::string &path)Parameters
ns: const std::string &The XML namespace URI for the schema in which the property is to be found.
path: const std::string &The name of the desired simple property. Note that XMP properties can have an XML substructure; this method can only retrieve values from simple textual properties.
Returns:
A string containing the XML text of the value of the specified property, or an empty string if no such property is found.It returns the XML text of the value of the specified property in the XMP metadata associated with the Document. The XMP metadata can represent all properties in the Document object's Info dictionary, as well as other properties.
import_acro_forms_data
boolimport_acro_forms_data(const std::string &path, AcroFormImportTypetype)Parameters
path: const std::string &The path on disk of the AcroFormsdata file to be imported.
type: AcroFormImportTypeThe format type the data type should be imported to. The supported types are XFDF, FDF, and XML.
Returns:
true indicates importing succeeded and false indicates an error occurredAcroForms data is imported from a supported format into the AcroForms document so its existing fields can be populated for example.
NOTE: This method is part of the APDFL Forms Extension that is available separately from APDFL. For more information, please see https://www.datalogics.com/pdf-form-functions.
import_xfa_forms_data
boolimport_xfa_forms_data(const std::string &path)Parameters
path: const std::string &The path on disk of the XFA form data file to be imported, the supported types of data that can be imported are XDP, XML, and XFD.
Returns:
true indicates importing succeeded and false indicates an error occurredXFA forms data is imported from a supported format into the XFA document so its existing fields can be populated for example.
NOTE: This method is part of the APDFL Forms Extension that is available separately from APDFL. For more information, please see https://www.datalogics.com/pdf-form-functions.
insert_pages
voidinsert_pages(intmerge_after, const Document &source, intstart_page, intnum_pages, PageInsertFlagsflags)Parameters
merge_after: intThe page number in doc after which pages from doc2 are inserted. The first page is 0. If Document.BeforeFirstPage is used, the pages are inserted before the first page in doc. Use Document.LastPage to insert pages after the last page in doc.
source: const Document &The document containing the pages that are inserted into doc.
start_page: intThe page number of the first page in doc2 to insert into doc. The first page is 0.
num_pages: intThe number of pages in doc2 to insert into doc. Use Document.AllPages to insert all pages from doc2 into doc.
flags: PageInsertFlagsFlags that determine what additional information is copied from doc2 into doc. It is an OR of the following constants: PageInsertFlags.Bookmarks, PageInsertFlags.Threads, PageInsertFlags.All
Returns:
voidInserts numPages pages from doc2 into doc. All annotations, and anything else associated with the page (such as a thumbnail image) are copied from the doc2 pages to the new pages in doc. This method does not insert pages if doc equals doc2.
The insertFlags parameter controls whether bookmarks and threads are inserted along with the specified pages. Setting this parameter to PageInsertFlags.All has two effects:
The parameters indicating which pages to insert are ignored: all the pages of doc2 are inserted. In addition to inserting the pages themselves, it also merges other document data from doc2 into doc: Named destinations from doc2 (of PDF 1.1 and later) are copied into doc. If there are named destinations in doc2 with the same name as some named destination in doc, the ones in doc retain their names and the copied named destinations are given new names based on the old ones, with distinguishing digits added. Actions and bookmarks referring to the old names are made to refer to the new names after being copied into doc. If it is also the case that mergeAfterThisPage denotes the last page of the document, then document metadata is merged, and the optional content properties are merged in a more symmetrical manner than would otherwise be the case.
Document logical structure from doc2 is copied into doc. If less than the whole of doc2 is being inserted, only those structure elements having content on the copied pages, and the ancestors of those elements, are copied into the logical structure tree of doc. The top-level children of the structure tree root of doc2 are copied as new top-level children of the structure tree root of doc; a structure tree root is created in doc if there was none before. The role maps of the two structure trees are merged, with name conflicts resolved in favor of the role mappings present in doc. Attribute objects having scalar values, or values that are arrays of scalar values, are copied. Class map information from doc2 is also merged into that for doc.
move_page
voidmove_page(intmove_to_after, intpage_to_move)Parameters
move_to_after: intThe new location of the page to move. The first page is 0. It may either be a page number, or the constant Document.BeforeFirstPage.
page_to_move: intThe page number of the page to move.
Returns:
voidMoves one page in a document.
operator=
Document &operator=(Document &&)Parameters
Returns:
Document &perm_request
boolperm_request(const std::string &password, PermissionRequestOperationoperation)Parameters
password: const std::string &- The document password which authorizes the change. Note - if this argument is set to a NULL (""), then the return will be an indicator of whether or not the requested permission is already set in this document, with no changes made to the PDF document.
operation: PermissionRequestOperation- the permissions on the PDF file which is to be set or checked.
Returns:
a boolean if the permission change is successful or if the permission was set.Request the permissions to be changed on a PDF document. This takes effect immediately
perm_request
boolperm_request(PermissionRequestOperationoperation)Parameters
operation: PermissionRequestOperation- The document password which authorizes the change. Note - if this argument is set to a NULL (""), then the return will be an indicator of whether or not the requested permission is already set in this document, with no changes made to the PDF document.
Returns:
a boolean if the permission change is successful or if the permission was set.Request the permissions to be changed on a PDF document. This takes effect immediately
voidprint(PrintUserParams ¶ms)Parameters
params: PrintUserParams &Parameters to control printing.
Returns:
voidPrints a PDF document or pages from a PDF document allowing the caller to specify options such as page size, rotation, and shrink-to-fit.
print_to_file
voidprint_to_file(PrintUserParams ¶ms, const std::string &path)Parameters
params: PrintUserParams &Parameters to control printing.
path: const std::string &The output file to be created.
Returns:
voidPrints a PDF document or pages from a PDF document allowing the caller to specify options such as page size, rotation, and shrink-to-fit.
The output is placed in the specified file.
remove_collection
voidremove_collection()Returns:
voidRemoveCollection Removes a collection dictionary from a document.
remove_name_tree
voidremove_name_tree(const std::string &name)Parameters
name: const std::string &The name of the NameTree to remove.
Returns:
voidRemoves the name tree inside the Names dictionary with the specified key name. It does nothing if no object with that name exists.
replace_pages
voidreplace_pages(intstart_page, const Document &source, intstart_page_source, intnum_pages, boolmerge_text_annots)Parameters
start_page: intThe first page number in doc to replace. The first page is 0.
source: const Document &The document from which pages are copied into doc.
start_page_source: intThe page number of the first page in doc2 to copy. The first page is 0.
num_pages: intThe number of pages to replace.
merge_text_annots: boolIf true, text annotations from doc2 are appended if they are different than all existing annotations on the page in doc. No other types of annotations are copied.
Returns:
voidReplaces the specified range of pages in one document with pages from another. The contents, resources, size and rotation of the pages are replaced. The bookmarks are not copied, because they are attached to the document, not to individual pages.
Annotations in the replaced pages are not replaced and remain with the page. Use DeletePages to remove annotations.
save
voidsave(SaveFlagsflags)Parameters
flags: SaveFlagsA bit field composed of an OR of the SaveFlags values.
Returns:
voidSaves a document to disk. If a full save is requested to the original path, the file is saved to a file system-determined temporary file, the old file is deleted, and the temporary file is renamed to newPath.
If the document was created with Document, at least one page must be added using CreatePage() or InsertPages() before a PDF Viewer can save the document.
A full save with linearization optimizes the PDF file. During optimization, all objects in a PDF file are rearranged, many of them acquiring not only a new file position, but also a new PDFObject number. At the end of the save operation, PDFL flushes its information of the PD layer and below to synchronize its in-memory state with the new disk file just written.
If the document has a signature, it will be saved incrementally regardless of the full save flag. This is required to preserve the exact contents of the document at the time of signing.
save
voidsave(SaveFlagsflags, const std::string &path)Parameters
flags: SaveFlagsA bit field composed of an OR of the SaveFlags values.
path: const std::string &The path to which the file is saved. A path must be specified when either SaveFlags.Full or SaveFlags.Copy are used for saveFlags. If SaveFlags.Incremental is specified in saveFlags, then newPath should be NULL. If SaveFlags.Full is specified and newPath is the same as the file's original path, the new file is saved to a file system-determined temporary path, then the old file is deleted and the new file is renamed to newPath.
Returns:
voidSaves a document to disk. If a full save is requested to the original path, the file is saved to a file system-determined temporary file, the old file is deleted, and the temporary file is renamed to newPath.
If the document was created with Document, at least one page must be added using CreatePage() or InsertPages() before a PDF Viewer can save the document.
A full save with linearization optimizes the PDF file. During optimization, all objects in a PDF file are rearranged, many of them acquiring not only a new file position, but also a new PDFObject number. At the end of the save operation, PDFL flushes its information of the PD layer and below to synchronize its in-memory state with the new disk file just written.
If the document has a signature, it will be saved incrementally regardless of the full save flag. This is required to preserve the exact contents of the document at the time of signing.
save
voidsave(SaveFlagsflags, std::ostream &output_stream)Parameters
flags: SaveFlagsoutput_stream: std::ostream &
Returns:
voidSave the document to an output stream.
secure
voidsecure(PermissionFlagspermissions, const std::string &owner_password, const std::string &user_password)Parameters
permissions: PermissionFlags- an "OR" of the types of PDF document specified by Permissions:
owner_password: const std::string &- optional PDF document owner password; pass null if not used.
user_password: const std::string &- optional PDF document user password; pass null if not used.
Returns:
voidIf the document has a security handler, it is retained. If the document does not have a security handler, it is assigned the "Standard" security handler with a 16-bit encryption key length. Access permissions as well as owner and user passwords are assigned to the PDF document. This method by default encrypts PDF's content as well as its metadata. To make selective encryption use appropriate overload of Secure() method.
The document must be saved for the changes to take effect. A full save is required.
secure
voidsecure(PermissionFlagspermissions, const std::string &owner_password, const std::string &user_password, EncryptionTypeencryption_type)Parameters
permissions: PermissionFlags- an "OR" of the types of PDF document specified by Permissions:
owner_password: const std::string &- optional PDF document owner password; pass null if not used.
user_password: const std::string &- optional PDF document user password; pass null if not used.
encryption_type: EncryptionType
Returns:
voidIf the document has a security handler, it is retained. If the document does not have a security handler, it is assigned the "Standard" security handler with a 16-bit encryption key length. Access permissions as well as owner and user passwords are assigned to the PDF document. This method by default encrypts PDF's content as well as its metadata. To make selective encryption use appropriate overload of Secure() method.
The document must be saved for the changes to take effect. A full save is required.
secure
voidsecure(PermissionFlagspermissions, const std::string &owner_password, const std::string &user_password, EncryptionTypeencryption_type, boolencrypt_metadata)Parameters
permissions: PermissionFlags- an "OR" of the types of PDF document specified by Permissions:
owner_password: const std::string &- optional PDF document owner password; pass null if not used.
user_password: const std::string &- optional PDF document user password; pass null if not used.
encryption_type: EncryptionTypeencrypt_metadata: bool
Returns:
voidIf the document has a security handler, it is retained. If the document does not have a security handler, it is assigned the "Standard" security handler with a 16-bit encryption key length. Access permissions as well as owner and user passwords are assigned to the PDF document. This method by default encrypts PDF's content as well as its metadata. To make selective encryption use appropriate overload of Secure() method.
The document must be saved for the changes to take effect. A full save is required.
set_author
voidset_author(const std::string &value)Parameters
value: const std::string &the author of the PDF document
Returns:
voidThe author of the PDF document.
set_base_uri
voidset_base_uri(const std::string &value)Parameters
value: const std::string &the Base URI of the PDF document
Returns:
voidThe Base URI of the PDF document.
set_creator
voidset_creator(const std::string &value)Parameters
value: const std::string &the creator of the PDF document
Returns:
voidThe creator of the PDF document.
set_delete_on_close
voidset_delete_on_close(boolvalue)Parameters
value: boolThe DeleteOnClose property
Returns:
voidThe document is based on a temporary file that must be deleted when the document is closed or saved.
set_info
voidset_info(const std::string &key, const std::string &value)Parameters
key: const std::string &The name of metadata to be set
value: const std::string &The value for metadata which will be set
Returns:
voidSets metadata information in a PDF document.
set_is_optimized
voidset_is_optimized(boolvalue)Parameters
value: boolThe IsOptimized property
Returns:
voidThe document is optimized. If this flag is cleared, the Adobe PDF Library does not save the file optimized. You can, therefore, linearize a PDF file without optimizing it. Optimizing without linearizing is not allowed, however. This flag can only be set, never cleared.
set_keywords
voidset_keywords(const std::string &value)Parameters
value: const std::string &the keywords of the PDF document
Returns:
voidThe keywords of the PDF document.
set_major_version
voidset_major_version(intversion)Parameters
version: intThe new major version number to be set in the document's file header.
Returns:
voidThe major PDF version number of the document. The PDF version is specified in the header of a PDF file in the string "%PDF-x.y" where x is the major version and y is the minor version. For example, version 1.2 has the string "%PDF-1.2". See Section I.2 in the PDF Reference.
Please note: Setting the major version on a document only changes the version number in the document's file header. It will NOT actually change the PDF's contents and it will NOT alter the PDF to conform to the standard of the new major version.
The new major version number will appear in the file header once the document is saved.
set_minor_version
voidset_minor_version(intversion)Parameters
version: intThe new minor version number to be set in the document's file header.
Returns:
voidThe minor PDF version number of the document. The PDF version is specified in the header of a PDF file in the string "%PDF-xx. yy" where xx is the major version and yy is the minor version. For example, version 1.2 has the string "%PDF-1 .2".
Please note: Setting the minor version on a document only changes the version number in the document's file header. It will NOT actually change the PDF's contents and it will NOT alter the PDF to conform to the standard of the new minor version.
The new minor version number will appear in the file header once the document is saved.
set_needs_save
voidset_needs_save(boolvalue)Parameters
value: boolThe NeedSave property
Returns:
voidThe document has been modified and needs to be saved.
set_page_labels
voidset_page_labels(const std::vector< PageLabel > &labels)Parameters
labels: const std::vector< PageLabel > &when a page label has an unknown numbering style
Returns:
voidThe list of PageLabel objects used in the document.
set_page_mode
voidset_page_mode(PageModemode)Parameters
mode: PageModethe pagemode to apply to the Document
Returns:
voidThe PageMode of the PDF document.
The default PageMode for a new Document is PageMode.NoPreference .
set_producer
voidset_producer(const std::string &value)Parameters
value: const std::string &the producer of the PDF document
Returns:
voidThe producer of the PDF document.
set_requires_full_save
voidset_requires_full_save(boolvalue)Parameters
value: boolThe RequiresFullSave property
Returns:
voidThe document cannot be saved incrementally; when it is saved using Document.Save(), the SaveFlags.Full flag must be specified. This flag can only be set, never cleared.
set_subject
voidset_subject(const std::string &value)Parameters
value: const std::string &the subject of the PDF document
Returns:
voidThe subject of the PDF document.
set_suppress_errors
voidset_suppress_errors(boolvalue)Parameters
value: boolThe SuppressErrors property
Returns:
voidDo not display errors.
set_title
voidset_title(const std::string &value)Parameters
value: const std::string &the title of the PDF document
Returns:
voidThe title of the PDF document.
set_xmp_metadata
voidset_xmp_metadata(const std::string &metadata)Parameters
metadata: const std::string &the XMP metadata associated with a document
Returns:
voidThe XMP metadata associated with a document.
The XMP metadata returned always represents all the properties in the Document's Info dictionary, and can also contain properties not present in the Info dictionary. This call is preferred to GetInfo, which only returns properties that are in the Info dictionary (although the older function is supported for compatibility).
set_xmp_metadata_array_item
voidset_xmp_metadata_array_item(const std::string &ns, const std::string &ns_prefix, const std::string &path, intindex, const std::string &value)Parameters
ns: const std::string &The XML namespace URI for the schema in which the property is to be found.
ns_prefix: const std::string &A brief string to be used as an abbreviation when creating the XML representation of the property. This string must not be empty.
path: const std::string &The name of the simple property to be modified.
index: intThe index in the metadata property array associated with the property.
value: const std::string &The new XML text value for the property.
Returns:
voidSets the value of an XMP metadata array item, associated with a document, based on an index.
set_xmp_metadata_property
voidset_xmp_metadata_property(const std::string &ns, const std::string &ns_prefix, const std::string &path, const std::string &value)Parameters
ns: const std::string &The XML namespace URI for the schema in which the property is to be found.
ns_prefix: const std::string &A brief string to be used as an abbreviation when creating the XML representation of the property. This string must not be empty.
path: const std::string &The name of the simple property to be modified.
value: const std::string &The new XML text value for the property.
Returns:
voidSets the value of an XMP metadata property associated with a document. The XMP metadata represents all the properties in pdDoc object's Info dictionary, and can also contain properties that are not in the Info dictionary.
unsecure
voidunsecure()Returns:
voidIf the document has a security handler, it is removed. If the document does not have a security handler, this method does nothing.
To remove the security handler, you must hold the PermissionRequestOperation.Secure permission, which you can obtain via Document.PermRequest. This call will throw an ApplicationException if you do not hold the Secure permission.
The document must be saved for the changes to take effect. A full save is required.
watermark
voidwatermark(Page &page, WatermarkParams ¶ms)Parameters
page: Page &The page to be added as a watermark.
params: WatermarkParams &Structure specifying how the watermark should be added to the document.
Returns:
voidAdds a Page as a watermark to a page range in the given document.
watermark
voidwatermark(WatermarkTextParams &text_params, WatermarkParams ¶ms)Parameters
text_params: WatermarkTextParams &The page to be added as a watermark.
params: WatermarkParams &Structure specifying how the watermark should be added to the document.
Returns:
voidAdds a Page as a watermark to a page range in the given document.