The pages interface gives access to manage and maintain the pages within the document.

  • retrieving pages
  • manipulating pages (set layout, name, etc)
  • add, remove and rearrange (change order) of pages
  • render the page (either getting the render directly or updating the mini preview available in the UI)

Note that this manages MegaEdit page objects, which are, depending on the configuration, full spreads or individual pages.

Hierarchy

  • Pages

Methods

  • This will add a new page to the document. The default tags, name and layout will be applied if set. The page mode is predetermined (single or spread) based on the product configuration.

    Parameters

    • Optional callback: ((page) => void)

      The callback will be triggered once the function has finished. If successfull, it will pass the new page object as a parameter. Otherwise it will pass null.

        • (page): void
        • Parameters

          Returns void

    • Optional afterPageOrId: string | Page

      An optional parameter to define the page (via object or id) after which to insert the new page. Otherwise it will be added at the end.

    • Optional ignorePageLimit: boolean

      Flag to control if the page limit should be ignored for the new page (e.g. would allow to go over the maximum count). This can only be used for server side code in the output generation stage.

    Returns void

  • Helper function to add media items to the current document - similar to the ME Upload UI. The media items are added full page. For multi page media items it can optionally add all pages by also inserting pages. It will also resize the pages to match the media.

    It does the following actions:

    • display a loading overlay during the action
    • add pages as necessary to match the start index parameter (aka this will add blank pages if necessary)
    • it will reuse existing pages, but will add enough pages for all the media items to add (for multi page media items) as necessary
    • clear all pages where we add media items
    • if dynamic canvas with varying aspect ratios is used, it will resize the pages to match the media item based on the minimum DPI.
    • position all the media centered to use up all the available space - including bleed
    • the fields will have the following settings -- FitWithoutCropping: no cropping is enabled on the image field -- DoNotSelect: the field cannot be selected -- NoImageDropTarget: the field will not act as a drop target for drag and drop -- Set the field tag as either ME_DIRECT_MEDIA_USAGE_FIT or ME_DIRECT_MEDIA_USAGE - indicating if the page fits directly the media item or not
    • Once we have added all media items, it will reinitialize the editor, clear the undo items, update all page previews, usage counters and also save the job
    • then it will remove the overlay screen. If it could not add all media items (e.g. we reached the max page count), an error message to the end user will be shown

    Parameters

    • index: number

      The zero based starting index where to insert the pages into. It will add pages if they do not exist if necessary, otherwise reuse existing pages. All pages will be cleared.

    • media: UserMediaItem

      The media item to insert. If this is a multi page media item, it will add all pages by also inserting pages based on the flag. If possible, it will resize the pages to match the media.

    • includeChildren: boolean

      Flag to control if all children of the media item should be added as well. This is only relevant for multi page media items.

    • Optional callback: ((success) => void)

      This optional callback is triggered once the process has finished (the overlay has been removed). The parameter will indicate if all media items could be added or not.

        • (success): void
        • Parameters

          • success: boolean

          Returns void

    Returns void

  • Return an array of all pages in the document.

    Returns Page[]

    An array of all pages in the document.

  • Return a single page either by it's unique id (id) or by it's zero-based index. Return null if not found

    Parameters

    • idOrIndex: string | number

      If this is a number, we will try to find the page by it's index. If this is a string, we will try to find the page by it's id.

    Returns Page

    The Page object if index or id is valid, otherwise null.

  • Return pages by their name. If exact is set to true, the name has to match exactly, otherwise it will return pages where the name parameter is within the page name. This will return an array, so it can be any number of matching results.

    Parameters

    • name: string

      The name of the string to search for.

    • Optional callback: null

      [Deprecated] Optional callback to be triggered once the search has finished with the results as parameter. Shouldn't be used anymore, please pass null instead.

    • Optional exact: boolean

      Boolean flag to control if the name has to match exactly or if it is enough if the name is contained within the page name.

    Returns Page[]

    An array of the found pages. If no pages are found, the array will be empty.

  • Clears content on the given page

    Parameters

    • pageOrIndexOrId: string | number | Page

      The page to clear. Identified by zero-based index, page id, page name or page object.

    • Optional drawingsOnly: boolean

      Optional flag to clear only drawings - that is only fields of type PathField. Default is false.

    • Optional callback: null

      [Deprecated] Optional callback to be triggered once the clear has finished. Shouldn't be used anymore, please pass null instead.

    • Optional keepDoNotSelectAndDelete: boolean

      Optional flag to delete all fields except those which are marked as doNotDelete and doNotSelect. Default is false. This is very useful to clear a page but keep the original design parts.

    Returns boolean

    Returns true if the page has been found and has been cleared, otherwise false.

  • Return the current number of pages in the document.

    Returns number

    The number of pages in the document.

  • Deletes a page from the document. Note that there are two areas which control the delete feature. At first comes the product configuration which defines which pages can never be deleted. In addition, a script can mark a page as not deletable. Only the first constraint will be checked here. The script setting is for UI only.

    Parameters

    • pageOrIndexOrId: string | number | Page

      The page to delete. Identified by zero-based index, page id, page name or page object.

    Returns boolean

    True if the page has been deleted, otherwise false.

  • Returns an informational object with the page information for the current job. This is fast to generate and should be used to get an overview of the pages instead of enumerating all pages.

    Returns PageInfo

    The page info object.

  • Changes the order of a page by moving it within the page listing forward or backwards based on the advance parameter. The advance parameter can be positive or negative and the code ensures that the page will not be moved outside of the page listing (e.g. you can use a large negative number to move the page to the start of the listing). The function will not ensure that the final page order is valid (e.g. in case of cover or spread start/end pages) - that needs to be done by the caller.

    Parameters

    • pageOrIndexOrId: string | number | Page

      The page to move. Identified by zero-based index, page id, page name or page object.

    • advance: number

      The number of pages to move the page. This can be positive or negative.

    Returns boolean

    True if the page has been moved, otherwise false.

  • Helper function to change the z-index of the fields on a page in one call. This is helpfull to rearrange the fields on a single page easily instead of adjusting the z-index of each field individually. Notes:

    • all fields in the list must exist on the page already, fields which do not exist will be simply ignored
    • this will affect the order of all fields on the page, not just the ones in the list
    • the fields listed will be at the back of the page in the same order as outlined here
    • any fields not listed on the page will come afterwards, the order will not be deterministic

    That means this should be called ideally only with all fields on that page to get a deterministic result.

    Parameters

    • pageOrIndexOrId: string | number | Page

      The page to rearrange. Identified by zero-based index, page id, page name or page object.

    • fieldOrIdList: string[] | BaseField[]

      The list of fields, either as field objects or as their ids. The order of this array will determine the order of the result.

    • ignoreUndo: boolean

      Flag to control if an undo record should be created.

    • ignoreEvent: boolean

      Flag to control if change events should be triggered

    Returns boolean

    Returns true if the page has been found and has been rearranged, otherwise false.

  • Helper function to generate a render of the given page. This will return a base64 encoded image of the page or false if the render failed.

    Parameters

    • pageOrIndexOrId: string | number | Page

      The page to render. Identified by zero-based index, page id, page name or page object.

    • size: number

      The size of the render identified by the width in pixels. The height will be calculated based on the aspect ratio of the page.

    • callback: ((image) => void)

      The callback will be triggered once the render is ready. It will pass as the first parameter the base64 encoded image or false if the render failed.

        • (image): void
        • Parameters

          • image: string | boolean

          Returns void

    • Optional renderPrintOnly: boolean

      Optional flag to control if only fields marked for print should be rendered or if all fields should be included. By default all fields are included.

    Returns void

  • Set the background to a determined background item. This will remove any existing background item.

    Parameters

    • pageOrIndexOrId: string | number | Page

      The page to set the background for. Identified by zero-based index, page id, page name or page object.

    • background: BackgroundItem

      The background item to set. This can be null to remove the background.

    • Optional position: SubPagePosition

      Optional position, this can be used to target only the left or right page of a spread. Default is Any.

    Returns boolean

    True if the background has been set, otherwise false.

  • Set the background to a determined color. This will remove any existing background item. Any MegaEdit color value can be used.

    Parameters

    • pageOrIndexOrId: string | number | Page

      The page to set the background for. Identified by zero-based index, page id, page name or page object.

    • color: string

      The color to set. Any MegaEdit color value can be used.

    • Optional position: SubPagePosition

      Optional position, this can be used to target only the left or right page of a spread. Default is Any.

    Returns boolean

    True if the background has been set, otherwise false.

  • Set the deletable flag for the page. Note that there are two areas which control the delete feature. At first comes the product configuration which defines which pages can never be deleted. In addition, scripts can flag certain pages which can never be deleted despite the configuration sees them as optional.

    Parameters

    • pageOrIndexOrId: string | number | Page

      The page to set the delete flag for. Identified by zero-based index, page id, page name or page object.

    • deletable: boolean

      The deletable flag. If false, the page cannot be deleted via the UI. If true, the system may still prevent deletion based on the product configuration (e.g. spread start/end pages, cover, min page count etc).

    Returns boolean

  • Sets a layout to a page. This will adjust the target page contents and copy data from the old layout to the new layout if possible.

    Parameters

    • pageOrIndexOrId: string | number | Page

      The page to set the layout for. Identified by zero-based index, page id, page name or page object.

    • layout: LayoutItem

      The new layout to set.

    • Optional index: number

      The zero based index of the subpage. This is only relevant for double pages. Default is 0 for single pages and full spread layouts as well as for spread pages for the left subpage. 1 is used for the right subpage of a spread page.

    • Optional callback: (() => void)

      The callback gets triggered once the layout has been applied.

        • (): void
        • Returns void

    Returns void

  • Set the name of a page. If the name is empty, it will be autogenerated.

    Parameters

    • pageOrIndexOrId: string | number | Page

      The page to set the name for. Identified by zero-based index, page id, page name or page object.

    • name: string

      The new page name or an empty string to use the autogenerated name.

    Returns boolean

    True if the name has been set, otherwise false.

  • Set the page tags to the given list. This will replace any existing tags.

    Parameters

    • pageOrIndexOrId: string | number | Page

      The page to set the tags for. Identified by zero-based index, page id, page name or page object.

    • tags: string[]

      The tag array. Note that each tag should be unique and may not contain the '|' character.

    Returns boolean

    True if the tags have been set, otherwise false.

  • Changes the visibility state of a page. This is only applied to the user interface. The page would be part of the output (delete the page to remove it from there).

    Parameters

    • pageOrIndexOrId: string | number | Page

      The page to set the visibility for. Identified by zero-based index, page id, page name or page object.

    • visible: boolean

      Flag to control if the page should be visible or not.

    Returns boolean

    True if the visibility has been set, otherwise false.

  • Call to update the small page preview within the UI for the page selector. This is because not all changes to the page will trigger an update of the preview - only when triggered via the UI. This can be used to update an individual page - or by passing null, all pages will be updated.

    Parameters

    • pageOrIndexOrId: string | number | Page

      The optional page to update. If null, all pages will be updated. Identified by zero-based index, page id, page name or page object.

    • Optional callback: ((hasUpdated) => void)

      The callback will be triggered once the update has finished. The parameter will indicate if the preview has been updated or not, which can be false if the page does not exist.

        • (hasUpdated): void
        • Parameters

          • hasUpdated: boolean

          Returns void

    Returns void

Generated using TypeDoc