ComPDFKit Web SDK
    Preparing search index...

    Class RubberStampCreateTool

    Base class for objects that fire named events. Listener arguments are passed by position.

    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 custom stamp (filling in defaults for missing fields) and fires stampsUpdated.

      Parameters

      • stamp: CustomStamp

        The custom stamp.

      Returns void

    • 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

    • Places the current stamp at location (centered on it; multiplied by setStampScaleFactor; drawn with setCustomDrawFunction first if set).

      Returns Promise<void>

    • Removes all document stamps and fires stampsUpdated.

      Returns 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

    • Custom stamp → image stamp (drawn by drawCustomStamp; width and height are half the canvas, in pt); falls back to the engine text stamp without a canvas.

      Parameters

      • stamp: CustomStamp

      Returns Promise<StampAnnotation>

    • Deletes by object reference (pass the objects from getCustomStamps); missing ones log a warning.

      Parameters

      • stamps: CustomStamp[]

      Returns void

    • Draws a custom stamp on canvas: a rounded background box, the title (smaller font when it does not fit), and the subtitle below when present (a date in moment format, with $currentUser replaced by the current user). Returns the stamp width (half the canvas pixels).

      Parameters

      • options: CustomStamp & {
            canvas?: HTMLCanvasElement;
            canvasParent?: HTMLElement;
            height?: number;
            width?: number;
        }
        • Optionalcanvas?: HTMLCanvasElement

          Canvas to draw on; a new canvas when omitted.

        • OptionalcanvasParent?: HTMLElement

          Element whose width limits the title width; 520 pixels when omitted.

        • Optionalheight?: number

          Stamp height (half the canvas pixels); 100 by default.

        • Optionalwidth?: number

          Minimum stamp width (half the canvas pixels); 300 by default.

      Returns number

    • Creates a stamp annotation for each custom stamp.

      Returns Promise<StampAnnotation[]>

      The stamp annotations, not added to the document.

    • Gets the custom stamps.

      Returns CustomStamp[]

      A copy of the custom stamp list.

    • Built-in standard stamp names.

      Returns string[]

    • Input of the last setDocumentStamps (a copy).

      Returns { options?: DocumentStampOptions; sources: DocumentStampSource[] }

      • Optionaloptions?: DocumentStampOptions

        The registration options.

      • sources: DocumentStampSource[]

        The registered stamp sources.

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

      Parameters

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

      Returns MouseLocation

    • Draws a preview image (dataURL): the stamp is fitted proportionally into canvasWidth × canvasHeight (getPreview).

      Parameters

      • annotation: Core.Annotations.Annotation
      • parameters: {
            canvasHeight: number;
            canvasWidth: number;
            direction?: "ltr" | "rtl";
            text?: string;
        }
        • canvasHeight: number

          Height of the preview image in pixels.

        • canvasWidth: number

          Width of the preview image in pixels.

        • Optionaldirection?: "ltr" | "rtl"

          'rtl' aligns the stamp to the right of the image; left by default.

        • Optionaltext?: string

          Replaces the text of a text stamp before drawing.

      Returns Promise<string>

    • One StampAnnotation (not placed) per standard stamp: Icon is the stamp name for standard stamps; image URLs become image stamps; document stamps follow.

      Returns Promise<StampAnnotation[]>

    • Gets the standard stamp names offered by the tool.

      Returns string[]

      A copy of the stamp names.

    • label is "title page".

      Parameters

      • label: string

      Returns boolean

    • Removes the preview that follows the pointer.

      Returns void

    • No stamp chosen (the current one is not a StampAnnotation).

      Returns boolean

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

      Parameters

      • e: KeyboardEvent

      Returns void

    • Fires annotationDoubleClicked; free text enters inline editing.

      Parameters

      • e: MouseEvent

      Returns void

    • With a stamp pending, a press places the stamp: pressing another annotation neither selects nor drags it; without a pending stamp, pressing an existing annotation selects and drags it as usual.

      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

    • 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

    • Draws on the stamp image before placement (callback(ctx, annotation?)); the placed stamp becomes an image stamp.

      Parameters

      Returns void

    • Fills in id and category for each (default 'Custom Stamp').

      Parameters

      • stamps: CustomStamp[]

      Returns void

    • Registers pages of another PDF as stamps (calling again replaces the previous registration). Note: each page is rendered as an image (at DOCUMENT_STAMP_SCALE), not a vector appearance; with cropVisibleContent the surrounding blank space (white or transparent) is cropped.

      Parameters

      • sources: DocumentStampSource[]
      • Optionaloptions: DocumentStampOptions

      Returns Promise<DocumentStampsResult>

    • 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

    • Width and height are multiplied by this on placement (1 by default; must be positive).

      Parameters

      • factor: number

      Returns void

    • Standard stamp names, or image URLs (http(s) / data:, made into image stamps); unknown names are removed.

      Parameters

      • stamps: string[]

      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 });
    • Shows the preview at the last pointer position (showPreview; our preview is drawn on the annotation layer).

      Returns Promise<void>

    • 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>

    • Keeps placing this stamp (Icon is a standard stamp name, or give a StampAnnotation) until another is chosen.

      Parameters

      • stamp:
            | StampAnnotation
            | {
                FillColor?: Color;
                Height?: number;
                Icon?: string;
                Opacity?: number;
                Width?: number;
            }
        • StampAnnotation
        • {
              FillColor?: Color;
              Height?: number;
              Icon?: string;
              Opacity?: number;
              Width?: number;
          }
          • OptionalFillColor?: Color

            Fill color; black by default.

          • OptionalHeight?: number

            Height in PDF points; 0 (natural size) by default.

          • OptionalIcon?: string

            Standard stamp name.

          • OptionalOpacity?: number

            Opacity from 0 to 1; 1 by default.

          • OptionalWidth?: number

            Width in PDF points; 0 (natural size) by default.

      Returns void

    annotation: Core.Annotations.Annotation | null

    Preview following the pointer (not added to the document).

    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.

    Events: {
        ANNOTATION_ADDED: "annotationAdded";
        CUSTOM_STAMPS_DELETED: "customStampsDeleted";
        STAMPS_UPDATED: "stampsUpdated";
    }

    Event names of the rubber stamp tool.

    Type Declaration

    • ReadonlyANNOTATION_ADDED: "annotationAdded"

      'annotationAdded': a stamp was placed.

    • ReadonlyCUSTOM_STAMPS_DELETED: "customStampsDeleted"

      'customStampsDeleted': custom stamps were deleted; receives the deleted stamps.

    • ReadonlySTAMPS_UPDATED: "stampsUpdated"

      'stampsUpdated': the standard, custom or document stamps changed.

    FILL_COLORS: string[]

    Default background colors of custom stamps.

    location: { pageNumber: number; x: number; y: number } | null

    Placement position (set by mouseLeftUp; can also be set before calling addStamp).

    Type Declaration

    • { pageNumber: number; x: number; y: number }
      • pageNumber: number

        Page number (1-based).

      • x: number

        X of the stamp center in PDF points.

      • y: number

        Y of the stamp center in PDF points.

    • null
    name: string

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

    TEXT_COLORS: string[]

    Default text colors of custom stamps.

    TIMESTAMP_CHOICHES: { id: string; value: string }[]

    Date format choices for custom stamp subtitles.

    Type Declaration

    • id: string

      Choice id.

    • value: string

      Date format of the subtitle ('other' for a custom format).