Documents
Library for interacting with document-properties / -components.
change_parent_page(...)
( record_id, pages = [], parent_page_name = "", remove_empty_page = False )
Change the parent-page on specified pages to a specified parent-page and link the parent-page-items to a provided record. Optionally remove a document-page, if it contains no pageitems.
| Parameters: | record_id (str) The record-id with which pageitems on the parent pages should be linked with. |
| pages (list[comet.CPage]) A list of document pages on which the parent pages should be changed. | |
| parent_page_name (str) The name of the parent-page including prefix (for example "A-Parent"). | |
| remove_empty_page (bool) Should document-pages without any pageitems be removed? | |
| Returns: | Whether the parent-pageitems were linked. |
| Return Type: | bool |
set_bookmarks(...)
( chapters = None, parent = None )
Creates bookmarks in the document based on a list of descriptions. These can contain nested descriptions to create nested bookmarks (recursively). See also Adding Bookmarks to the Document
| Parameters: | chapters (list[dict]) A list of dictionaries that describe the bookmarks by keys: page(int|comet.CPage)name (str) optional, uses empty string as name if missingindex (int) optional, adds bookmark to end if missingchildren (list[dict]) optional, has to match the same dict-structure and can contain nested children |
| parent (comet.CBookmark|None) A bookmark, that the new bookmark will be added to as child. New bookmark is added to top-level if missing. | |
| Returns: | A list of the bookmarks that were created on the top-level. |
| Return Type: | list[comet.CBookmark] |
Example:
bookmarks = [
{"page":0,"name":"My First Page","index":0, "children":[
{"page":1,"name":"My First Child","index":1, "children":[
{"page":2,"name":"My Nested Child","index":2}
]}
]},
{"page":comet.gDocument.getPages()[-1],"name":"My Last Page","index":-1},
]
document_lib.set_bookmarks(bookmarks)

set_document_metadata(...)
( attributes = None )
Set document-metadata based on a collection of attributes instead of setting each metadata-attribute separately. Keep in mind that comet expects correct keys and value-types.
Keys and Types
kTitle (string)
kDescription (string)
kAuthor (string)
kAuthorTitle (string)
kAuthorDescription (string)
kKeys (list[str])
kCopyRight (string)
kCopyRightURL (string)
kCopyRightState (int)
kRating (int)
Also refer to the Comet-documentation
| Parameters: | attributes (dict) A dictionary with valid key-values for PDF-Metadata. For examples refer to: PDF-Metadata & get_comet_pdf_metadata |
| Returns: | A dictionary of all the metadata that was set. |
| Return Type: | dict |
remove_empty_trailing_pages()
Removes pages starting at the end of the document until a comet.CLink is found on a page.
| Returns: | Amount of pages that were removed. |
| Return Type: | int |
remove_pages_after(...)
(remaining_page: comet.CPage)
Removes all pages after a given page in a document.
| Parameters: | remaining_page (comet.CPage) The page last page in front of the pages that should be removed. Can't be the last page in the document. |
| Returns: | Amount of pages that were removed. |
| Return Type: | int |
get_docattribute_as_float(...)
(key:str):
Reads the document-attribute of the given key and tries to convert it to a float-value.
| Parameters: | key (str) Key of a valid documen-attribute. |
| Returns: | The float-value of the document-attribute or None if the value can't be converted. |
| Return Type: | float|None |
get_pagetemplate_bbox(...)
(page, slot_index = 0):
Creates a CRect-Object of the dimensions of the pagetemplate-element of the given page.
| Parameters: | page (comet.CPage) A valid page in the document. |
| slot_index (int) The index of the Pagetemplate's element. | |
| Returns: | The Bbox of selected pagetemplate-element. |
| Return Type: | comet.CRect |
toggle_layer_visibility(...)
(visible = True, layer_name = "DEMO")
Sets a layer's visibility to the specified status and moves it to the top. Ideal for showing or hiding a layer with highlighted elements like a watermark.
| Parameters: | visible (bool) Whether the layer's visibility should be set to "visible" or "not visible". |
| layer_name (str) Name of the document's layer whose visibility should be chnaged. | |
| Returns: | Whether the layer was set to visible or not. |
| Return Type: | bool |