comet.CPage

class comet.CPage

This section describes all functions for the comet.CPage class.

InDesign® comet_pdf® CPage represents a document page

Illustrator® CPage represents a document artboard

Methods

CPage.getDocument()

Get the document this page belongs to.

Returns:

The document

Return type:

CDocument

Available:

InDesign® comet_pdf® Illustrator®

CPage.getSpread()

Get the spread this page belongs to.

Returns:

The containing spread.

Return type:

CSpread

Available:

InDesign® comet_pdf®

CPage.getIndexInSpread()

Get the spread-relative index of this page.

Returns:

The page index related to its spread

Return type:

int

Raises:

CometError – On internal error

Available:

InDesign® comet_pdf®

CScript:

page::get_spread

CPage.getUID()

Get the UID of this page as an int.

Returns:

The UID of this page

Return type:

int

Raises:

CometError – On internal error

Available:

InDesign® comet_pdf®

CScript:

page::get_uid

CPage.getIndex()

Get the 0-based index of this page.

Returns:

The page index

Return type:

int

Raises:

CometError – On internal error

Available:

InDesign® comet_pdf® Illustrator®

CPage.setIndex(index)

Set the index of this page by moving the page to the desired index and moving everything behind the index back.

This will reshuffle the spreads

Attention: The resulting index may not be the one provided by the index parameter, e.g. when moving the page with index 0 to before index 1, the resulting index is still 0.

Parameters:

index (int) –

The desired result index

  • 0: The page becomes the new first page

  • <0 or >= page count: The page becomes the new last page

  • Else: The target index

Return type:

None

Raises:
Available:

InDesign® comet_pdf®

CScript:

page::move

CPage.getType()

Get the type of the page (left/right/unisex)

Returns:

The page type.

One of Page types

Return type:

int

Raises:

CometError – On internal error

Available:

InDesign® comet_pdf®

CScript:

page::get_type

CPage.getBounds()

Get the bounding box of this page.

Returns:

The page bounds in global space.

Return type:

CRect

Raises:

CometError – On internal error

Available:

Illustrator®

CPage.getSize(marginRelative=False)

Get the size of this page.

Parameters:

marginRelative (bool) –

Subtract the margins from the page size?

  • True: Without margins

  • False: Full page size

Returns:

The page size as (width, height)

Return type:

tuple[float, float]

Raises:
Available:

InDesign® comet_pdf® Illustrator®

CScript:

page::get_size

CPage.setSize(width, height, refPoint=0)

Set the size of this page.

InDesign® comet_pdf®

In page-based layouts such as those generated by InDesign® and comet_pdf, the size of the pages is a fundamental information and changing page sizes will lead to significant differences in the output.

This function only changes the page size! Apart from a possible re-adjustment of the frames according to the given reference point no reorganization of the page contents will be made! This means in particular:

  • Frame assignments to spreads (InDesign®) or pages (comet_pdf) remain unchanged. If frames fall geometrically from the spread or the page, they become invisible in the exported PDF.

  • There is no customization of the parent pages and their elements!

  • Any page templates remain unchanged.

  • InDesign® partially realizes changes to the page size by shifting the page coordinate system of the page. This can also change the frame coordinates.

Parameters:
Return type:

None

Raises:
  • TypeError – When parameter types are invalid

  • ValueError

    • When parameters width or height have invalid value (< 1.0)

    • When parameter refPoint has invalid value

  • CometError – On internal error

Available:

InDesign® comet_pdf® Illustrator®

CScript:

page::set_size

CPage.getPosition()

Get the position of this page.

Returns:

The position in global space as [x, y]

Return type:

tuple[float, float]

Raises:

CometError – On internal error

Available:

Illustrator®

CPage.setPosition(x, y, refPoint=0)

Set the position of this page.

Parameters:
Return type:

None

Raises:
Available:

Illustrator®

CPage.getMargins(facingRule=0)

Get the page margins. Right and bottom margins are based on right/bottom page size.

Parameters:

facingRule (int) –

How to return values for facing pages.

  • 0: inner, top, outer, bottom

  • 1: left, top, right, bottom

Returns:

The page margins as (insideLeft, top, outsideRight, bottom)

Return type:

tuple[float, float, float, float]

Raises:
Available:

InDesign® comet_pdf®

CScript:

page::get_margins

CPage.setMargins(insideLeft, top, outsideRight, bottom, facingRule=0)

Set the margins of this page

Parameters:
  • insideLeft (float) – New inside (for facing pages) or left margin

  • top (float) – New top margin

  • outsideRight (float) – New outside (for facing pages) or right margin

  • bottom (float) – New bottom margin

  • facingRule (int) –

    To what do the new values refer?

    • 0: inner, top, outer, bottom

    • 1: left, top, right, bottom

Return type:

None

Raises:
  • TypeError – When parameter types are invalid

  • ValueError

    • When parameter margin values are invalid (< 0.0)

    • When parameter facingRule has invalid value

  • CometError – On internal error

Available:

InDesign® comet_pdf®

CScript:

page::set_margins

CPage.getColumnCount()

Get the column count of this page.

Returns:

The column count

Return type:

int

Raises:

CometError – On internal error

Available:

InDesign® comet_pdf®

CScript:

page::count_columns

CPage.getColumnGutter()

Get the column gutter of this page.

Returns:

The column gutter

Return type:

float

Raises:

CometError – On internal error

Available:

InDesign® comet_pdf®

CScript:

page::count_columns

CPage.getName(includeSectionName=True, useIntStyle=True, numberingType=0, abbreviate=True)

Get the name of this page.

Parameters:
  • includeSectionName (bool) –

    Include the section name?

    Illustrator® Ignored

  • useIntStyle (bool) –

    • True: Use arabic numerals in string

    • False: Use the style of this section

    Illustrator® Ignored

  • numberingType (int) –

    Which page numbering settings are to be used?

    • 0: InDesign® settings

    • 1: Document settings

    • 2: Pages counted beginning from 1

    Illustrator® Ignored

  • abbreviate (bool) –

    Use abbreviation?

    Illustrator® Ignored

Return type:

None

Raises:
CScript:

page::get_str_by_index

Available:

InDesign® comet_pdf® Illustrator®

CPage.getPageItems(recursive=False)

Get all pageitems on this page.

Parameters:

recursive (bool) –

Whether to resolve hierarchies completely.

  • False Only return root pageitems.

  • True Flatten hierarchies, omitting groups from the result.

Returns:

The pageitems of the page.

Return type:

list[CPageItem]

Raises:
Available:

InDesign® comet_pdf® Illustrator®

CScript:
CPage.getFrames(subFrames=False, placeHolders=[], layers=[], cometGroups=[], names=[])

Get all frames on this page applying various optional filters.

Parameters:
  • subFrames (bool) – Insert subframes into the result?

  • placeHolders (list[int]) –

    Restrict the result to frames with placeholder IDs in this list.

    • Empty list : Do not impose restrictions

    • [-1] : Restrict to all frames with placeholders

  • layers (list[str] | list[CLayer]) –

    Restrict the result to frames on the provided layers.

    The parameter type can be:

    When the parameter is list [CLayer], all layers must belong to the same document as this page.

  • cometGroups (list[int]) –

    Restrict the result to frames with the provided comet group IDs.

    • Empty list : Do not impose restrictions

  • names (list[str]) –

    Restrict the result to frames with the provided names.

    Entries may also contain regular expressions.

    • Empty list : Do not impose restrictions

Returns:

A list of frames matching the provided criteria on this page

Return type:

list[CFrame]

Raises:
CScript:
Available:

InDesign® comet_pdf® Illustrator®

CPage.getMasterPage()

Fetch the name of the master page of this page.

Returns:

The full name of the master page

Return type:

str

Raises:

CometError – On internal error

Available:

InDesign® comet_pdf®

CScript:

page::get_masterpage

CPage.setMasterPage(masterPage, resize=False)

Change the master mage of this page.

Parameters:
  • masterPage (str) –

    Prefix and name of an existing master page.

    e.g. ‘A-Mustervorlage’

  • resize (bool) –

    Change page size according to the master page?

    • True: Yes, change page size if necessary

    • False: No, keep current page size

Return type:

None

Raises:
Available:

InDesign® comet_pdf®

CScript:

page::set_masterpage

CPage.loadMasterItems()

Load the placeholders for the frames from the master page of a page.

The frames taken from the respective master page of a document page are not automatically processed when editing the placeholders.

In order for master page elements to be treated as independent page content, they must first be localized. This localization can be done manually in the document. When changing the associated (non-localized) frame of the master page, only the frame properties from the master page that have not been overwritten are transferred.

Once frames have been localized, they can be edited and changed like normal frames. To localize a master page frame with loadMasterItems(), the frame must be linked to a placeholder with an ID > 0. An additional link to a product is not necessary, so the frame may have the record ID [0, 0, 0, ‘’].

Repeated calls of loadMasterItems() are permitted.

The function automatically recognizes whether a master page frame has already been localized. In this case, the placeholders of the localization are processed without localizing the frame again.

Returns:

The newly localized frames.

Return type:

list[CFrame]

Raises:

CometError – On internal error

Available:

InDesign® comet_pdf®

CScript:

page::masteritems_load

CPage.getInfo(attribute)

Retrieve information about a page template.

Parameters:

attribute (int) –

The attribute to query.

One of Page info.

Returns:

The value for the queried attribute.

The return type depends on the attribute.

Return type:

None

Raises:
Available:

InDesign® comet_pdf®

CScript:

page::get_info

CPage.setInfo(attribute, value)

Set information about a page template.

Parameters:
  • attribute (int) –

    The attribute to set.

    One of Page info.

  • value (int | str | bool) –

    The value to set.

    The type must match the attribute.

Return type:

None

Raises:
Available:

InDesign® comet_pdf®

CScript:

page::get_info

CPage.createSnapshot(outPath, format='JPG', options={})

Create a preview snapshot of this page and save it as a file.

Parameters:
  • outPath (str) – The absolute file path to save the snapshot to.

  • format (str) –

    Target format of the preview.

    The following values are valid:

    • InDesign® Illustrator® ‘JPG’, ‘JPEG’

    • Illustrator® ‘PNG’

    • InDesign® ‘GIF’, ‘GIFF’

    • InDesign® ‘TIF’, ‘TIFF’

  • options (dict) –

    Export options.

    Keys in this dictionary are of type str.

    Depending on the chosen export format, for following options are available:

    All formats

    ’kResolution’

    The target resolution in DPI.

    • Type: float

    • Default: 144.0

    PNG

    ’kBackground’

    The background color setting to apply.

    • Value type: str

    • Default: ‘kTransparent’

    Allowed values:

    • ’kTransparent’

      Transparent background

    • ’kWhite’

      White background

    • ’Black’

      Black background

    JPG

    ’kQuality’

    • Value type: int

    • Default: 10

    JPG quality in range 0-10.

    Illustrator® only.

Return type:

None

Raises:
Available:

InDesign® Illustrator®

CScript:

image::snapshot_page

CPage.remove(reshuffle=True)

Deletes this page from it’s document.

All subsequent calls to this page’s functions will fail.

At least one page has to remain in the document, so if this is the last page this function will fail.

Parameters:

reshuffle (bool) –

Should the following pages be rearranged?

comet_pdf® Ignored, the value is always True

Illustrator® Ignored

Return type:

None

Raises:
Available:

InDesign® comet_pdf® Illustrator®

CScript:

page::remove

Special methods

CPage.__repr__()

String representation.

Returns:

InDesign® comet_pdf®

<CPage> Index: Index | Name: Name | Type: Type

Illustrator®

<CPage> Index: Index | Name: Name

Example
<CPage> Index: 0 | Name: 1 | Type: Right
<CPage> Index: 1 | Name: 2 | Type: Left

Return type:

str