ComPDFKit Web SDK
    Preparing search index...

    Class CropCreateTool

    ToolNames.RECTANGLE: drag out a rectangle; after setSnapMode both corners snap to the page's vector content.

    Hierarchy (View Summary)

    Index
    • get ALLOW_ANNOTS_OUTSIDE_PAGE(): boolean

      Whether annotations can be dragged outside the page (off by default: dragging stops at the page edge and does not move in a direction where the annotation is larger than the page).

      Returns boolean

    • set ALLOW_ANNOTS_OUTSIDE_PAGE(allow: boolean): void

      Whether annotations can be dragged outside the page (off by default: dragging stops at the page edge and does not move in a direction where the annotation is larger than the page).

      Parameters

      • allow: boolean

      Returns void

    • With the link tool on, pressing a hand-drawn link selects, drags and resizes it (otherwise a click follows it).

      Returns boolean

    • Adds a listener for an event. Adding the same function twice for one event has no effect.

      Type Parameters

      • K extends keyof ToolEvents

      Parameters

      • name: K

        Event name.

      • fn: (...args: ToolEvents[K]) => void

        Listener, called with the event arguments.

      • Optionaloptions: { once?: boolean }

        Listener options.

        • Optionalonce?: boolean

          When true, the listener is removed after it runs once.

      Returns void

    • Crops pages by the distances between the crop box and the page edges, then clears the box. Which pages are cropped depends on the crop mode. Does nothing without a crop box.

      Returns Promise<void>

    • Called when the context menu is requested on the viewer; does nothing in the base class.

      Parameters

      • _e: MouseEvent

        The mouse event.

      Returns void

    • Turns off automatic text selection by the edit tool (sets ENABLE_AUTO_SWITCH to false).

      Returns void

    • Turns on automatic text selection by the edit tool (sets ENABLE_AUTO_SWITCH to true).

      Returns void

    • The box stays in the tool and is not added to the document; boxes that are too small count as accidental clicks.

      Returns void

    • Gets the crop mode.

      Returns CropMode

      The mode; 'SINGLE_PAGE' by default.

    • Whether a crop box has been drawn and not yet applied or cleared.

      Returns boolean

      True while cropping.

    • Viewport event → the page and page coordinates under the pointer (unrotated page, top-left origin, pt).

      Parameters

      • e: Pick<MouseEvent, "clientX" | "clientY">

      Returns MouseLocation

    • Gets the pages cropped in 'MULTI_PAGE' mode.

      Returns number[]

      A copy of the page numbers (1-based).

    • Snap mode (a SnapModes value or combination): once set, snaps to the page's vector content both before and while drawing (see tools/snapping.ts).

      Returns number | undefined

    • Called when a key is pressed while the viewer has focus; does nothing in the base class.

      Parameters

      • e: KeyboardEvent

      Returns void

    • Double-clicking an existing annotation: same as the selection tool (fires annotationDoubleClicked; free text enters inline editing).

      Parameters

      • e: MouseEvent

      Returns void

    • Called when the left mouse button or a touch goes down on the viewer; does nothing in the base class.

      Parameters

      • e: PointerEvent

      Returns void

    • Called when the left mouse button or a touch is released; does nothing in the base class.

      Parameters

      • e: PointerEvent

      Returns void

    • Called when the pointer moves over the viewer; does nothing in the base class.

      Parameters

      • e: PointerEvent

      Returns void

    • Called when the right mouse button goes down on the viewer; does nothing in the base class.

      Parameters

      • _e: PointerEvent

        The pointer event.

      Returns void

    • Applies the same crop box to these pages (switches to MULTI_PAGE and records the pages).

      Parameters

      • pageNumbers: number[]

      Returns void

    • Removes a listener, or every listener of the event when fn is omitted.

      Type Parameters

      • K extends keyof ToolEvents

      Parameters

      • name: K

        Event name.

      • Optionalfn: (...args: ToolEvents[K]) => void

        The function that was passed to addEventListener.

      Returns void

    • Removes the crop box.

      Returns void

    • Sets the crop mode. Throws for unknown modes.

      Parameters

      • mode: CropMode

        'SINGLE_PAGE', 'ALL_PAGES' or 'MULTI_PAGE'.

      Returns void

    • Sets the minimum size when resizing annotations (static, shared by all select / edit tools).

      Parameters

      • getter: SizeGetter | null

      Returns void

    • Sets the name of the tool.

      Parameters

      • name: string

        The tool name.

      Returns void

    • Sets the pages cropped in 'MULTI_PAGE' mode (the box's page when empty).

      Parameters

      • pages: number[]

        Page numbers (1-based).

      Returns void

    • Changes the tool's default style (used by annotations created afterwards); fires toolUpdated.

      Parameters

      • styles: Record<string, unknown>

      Returns void

      const { documentViewer, Annotations, Tools } = instance.Core;
      const freeTextTool = documentViewer.getTool(Tools.ToolNames.FREETEXT);
      freeTextTool.setStyles({ TextColor: new Annotations.Color(0, 0, 0), FontSize: '14pt', Font: 'Helvetica' });
      documentViewer.getTool(Tools.ToolNames.HIGHLIGHT).setStyles({ StrokeColor: new Annotations.Color(0, 255, 0), Opacity: 0.6 });
    • Called on a tap (a touch press and release without moving); does nothing in the base class.

      Parameters

      • _e: PointerEvent

        The pointer event.

      Returns void

    • A listener that throws does not affect the others; the error is reported through logger.error.

      Type Parameters

      • K extends keyof ToolEvents

      Parameters

      • name: K
      • Optionalargs: ToolEvents[K]

      Returns void

    • Like trigger, but awaits the Promise returned by each listener in turn; a failing listener does not affect the others.

      Type Parameters

      • K extends keyof ToolEvents

      Parameters

      • name: K
      • Optionalargs: ToolEvents[K]

      Returns Promise<void>

    annotation: Core.Annotations.Annotation | null

    The annotation being drawn, not yet added to the document.

    CropModes: {
        ALL_PAGES: "ALL_PAGES";
        MULTI_PAGE: "MULTI_PAGE";
        SINGLE_PAGE: "SINGLE_PAGE";
    }

    Values of the crop mode.

    Type Declaration

    • ReadonlyALL_PAGES: "ALL_PAGES"

      Crop all pages.

    • ReadonlyMULTI_PAGE: "MULTI_PAGE"

      Crop the pages set with setPagesToCrop.

    • ReadonlySINGLE_PAGE: "SINGLE_PAGE"

      Crop the page the crop box is on.

    cursor: string

    The tool's own cursor: used when switching in and when hovering over empty space (default for the edit tool, crosshair for creation tools, text for text tools, grab for pan...).

    defaults: Record<string, unknown>

    Default style of annotations created by the tool (such as StrokeColor, StrokeThickness, Opacity); changed with setStyles.

    ENABLE_ANNOTATION_HOVER_CURSORS: boolean

    Changes the cursor on hover by what is under the pointer (annotations, handles, text); the stamp, attachment, eraser and marquee zoom tools turn it off, and it is turned back on when they switch out (Tool.ENABLE_ANNOTATION_HOVER_CURSORS).

    ENABLE_AUTO_SWITCH: boolean

    Whether the edit tool selects text automatically when hovering over text (the edit tool selects text itself, so when this is off it neither selects text nor shows the text cursor; the instance enable / disableTextSelection must also be on). Turned off on touch screens.

    name: string

    Name the tool is registered under (one of ToolNames).