Document Solutions Image Viewer is a fast JavaScript based client-side Image Viewer that runs in all major browsers.

Note that DsImageViewer is the new name for GcImageViewer, with the same API.

During this transition period we are publishing both versions, but it is recommended that you switch to using DsImageViewer when possible.

Example

var viewer = new DsImageViewer("#root");

Hierarchy

Implements

Methods

  • Gets the viewer instance using the host element or host element selector

    Example

    var viewer = DsImageViewer.findControl("#root");
    

    Parameters

    • selector: string | HTMLElement

    Returns undefined | GcImageViewer

  • Starts long-running operation and displays progress window while operation is running.

    Parameters

    • task: ((callbacks: TaskCallbacks) => Promise<void>)
        • (callbacks: TaskCallbacks): Promise<void>
        • Parameters

          • callbacks: TaskCallbacks

          Returns Promise<void>

    • Optional settings: TaskSettings

    Returns Promise<void>

  • Updates the panel visibility.

    Parameters

    • panelKey: PanelHandle
    • Optional visible: boolean

    Returns void

  • Updates panel settings such as visibility, label or "enabled" status.

    Parameters

    • panelKey: PanelHandle
    • settings: Partial<PanelSettings>

    Returns void

  • Gets the current panel state.

    Parameters

    • panelKey: PanelHandle

    Returns null | PanelSettings

  • Orders and filters panel items. '*' indicates "the rest of panels". 'sep'/'separator' indicated menu separator.

    Parameters

    • layout: string[]

    Returns void

  • Deprecated

    use expandPanel() instead

    Parameters

    • panelKey: PanelHandle

    Returns void

  • Updates activeTopPanelId for to show/hide panel with setting.location = 'top' (id = null to hide panel)

    Parameters

    • id: null | string

    Returns void

  • Updates activeBottomPanelId for to show/hide panel with setting.location = 'bottom' (id = null to hide panel)

    Parameters

    • id: null | string

    Returns void

  • Resets report and cancel current session if any.

    Returns Promise<void>

  • Loads the report (no UI), so caller has to process load result and report error if any.

    Parameters

    • moniker: DocumentMoniker
    • Optional token: CancellationToken

    Returns Promise<LoadResult>

  • Searches currently opened document for the text.

    Parameters

    • __namedParameters: SearchOptions
    • resultFn: ((result: SearchResult) => void)
        • (result: SearchResult): void
        • Parameters

          • result: SearchResult

          Returns void

    • Optional progressFn: ((progress: { pageIndex: number; pageCount: null | number }) => void)
        • (progress: { pageIndex: number; pageCount: null | number }): void
        • Parameters

          • progress: { pageIndex: number; pageCount: null | number }
            • pageIndex: number
            • pageCount: null | number

          Returns void

    • Optional cancel: CancellationToken

    Returns Promise<SearchStatus>

  • Navigates to a page containing the result and highlights found text.

    Parameters

    • result: SearchResult

    Returns Promise<void>

  • Remove and dispose image layer given by argument layerOrIndex.

    Parameters

    • layerOrIndex: string | number | IImageLayer

      Image layer or image layer index or image layer name.

    Returns void

  • Call this method in order to apply changed options.

    Example

    viewer.applyOptions();
    

    Returns void

  • Call this method in order to apply changes in @see:toolbarLayout.

    Example

    viewer.toolbarLayout.viewer.default = ["open", "save"];
    viewer.applyToolbarLayout();

    Example

       var viewer = new DsImageViewer(document.querySelector("#viewer"));
    var toolbar = viewer.toolbar;
    var toolbarLayout = viewer.toolbarLayout;
    toolbar.addItem({
    key: 'custom-action',
    icon: { type: "svg", content: '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path style="fill: #205F78;" d="M20.25 12l-2.25 2.25 2.25 2.25-3.75 3.75-2.25-2.25-2.25 2.25-2.25-2.25-2.25 2.25-3.75-3.75 2.25-2.25-2.25-2.25 2.25-2.25-2.25-2.25 3.75-3.75 2.25 2.25 2.25-2.25 2.25 2.25 2.25-2.25 3.75 3.75-2.25 2.25 2.25 2.25z"></path></svg>' },
    title: 'Custom action',
    checked: false, enabled: false,
    action: function () {
    alert("Implement your action here.");
    },
    onUpdate: function (args) {
    return {
    enabled: true,
    checked: false,
    title: 'Custom action title'
    }
    }
    });
    toolbarLayout.viewer.default.splice(0, 0, "custom-action");
    viewer.applyToolbarLayout();

    Returns void

  • Add plug-in instance which is used to add new functionality to the DsImageViewer.

    Example

    var viewer = new DsImageViewer("#root");
    var rotationPlugin = new RotationPlugin();
    viewer.addPlugin(rotationPlugin);

    Parameters

    Returns boolean

  • Remove window keyboard listener.

    Parameters

    • uniqueKey: string

    Returns void

  • Used preliminarily by the plugin developers to configure the main toolbar layout.

    Example

    // Apply a custom layout to insert "zoomIn" and "zoomOut" buttons at position 2 for the "PaintTools" plugin.
    viewer.configurePluginMainToolbar(2, ["zoomIn", "zoomOut"]);

    Returns

    void

    Parameters

    • pos: undefined | number | boolean

      The position where the buttons should be inserted. Use false or -1 to skip insertion. Undefined means the position will be determined automatically.

    • buttonsToInsert: string[]

      An array of button keys to be inserted.

    Returns void

  • Retrieves the point location from the pointer event provided by the 'event' parameter. The returned point is relative to the active canvas element

    Parameters

    • event: PointerEvent | MouseEvent

      DOM Pointer or Mouse event object.

    • includeDpi: boolean = false

    Returns PointLocation

  • Sets the cursor style for the image viewer

    Returns

    Example

    // Set rotate cursor during image rotation
    viewer.setCursor('rotate');

    Example

    // Set resize cursor when hovering over edges
    viewer.setCursor('nwse-resize');

    See

    GlobalCursorType for all available cursor options

    Parameters

    Returns IImageViewer

  • Resets the cursor to default style

    Returns

    Example

    // Reset cursor when operation completes
    viewer.resetCursor();

    Example

    // Reset cursor on mouse leave
    viewerElement.addEventListener('mouseleave', () => {
    viewer.resetCursor();
    });

    Returns IImageViewer

  • Toggles between specified cursor and default style

    Returns

    Example

    // Toggle grab cursor during drag operations
    viewer.toggleCursor(isDragging ? 'grab' : false);

    Example

    // Toggle zoom cursor based on modifier key
    document.addEventListener('keydown', (e) => {
    if (e.ctrlKey) {
    viewer.toggleCursor('zoom-in');
    }
    });

    Parameters

    Returns IImageViewer

  • Load image data using given data url.

    Parameters

    • dataUrl: string
    • Optional destinationSize: { width: number; height: number }
      • width: number
      • height: number

    Returns Promise<ImageData>

  • Display confirmation dialog.

    Example

    const confirmResult = await viewer.confirm("Apply changes?", "info", "Confirm action", ["Yes", "No", "Cancel"]);
    if (confirmResult === "Yes") {
    // put your code here
    } else if (confirmResult === "No") {
    // put your code here
    } else {
    // put your code here
    }

    Parameters

    • Optional confirmationText: string | Element
    • Optional level: "error" | "info" | "warning"
    • Optional title: string
    • Optional buttons: ConfirmButton[]

    Returns Promise<boolean | ConfirmButton>

  • Remove plug-in instance from the DsImageViewer.

    Example

    var viewer = new DsImageViewer("#root");
    var rotationPlugin = new RotationPlugin();
    viewer.addPlugin(rotationPlugin);

    viewer.removePlugin(rotationPlugin.id);

    Parameters

    Returns void

  • Show about dialog.

    Returns void

  • Finds a viewer plugin by its id.

    Example

    // find imageFilters plugin:
    var imageFilters = viewer.findPlugin("imageFilters");
    // find pageTools plugin:
    var pageTools = viewer.findPlugin("pageTools");

    Parameters

    • pluginId: string

    Returns null | IViewerPlugin

  • Remove all plug-ins.

    Example

    viewer.removePlugins();
    

    Returns void

  • Clear undo storage.

    Returns void

  • Create new empty image.

    Example

    await viewer.newImage({ width: 300, height: 300, fileName: "myImage.png" });
    

    Parameters

    • Optional options: { width?: number; height?: number } & OpenParameters

    Returns Promise<any>

  • Use this method to close and release resources occupied by the DsImageViewer.

    Returns void

  • Show activity spinner.

    Example

    viewer.showActivitySpinner();
    

    Parameters

    • Optional container: HTMLElement

    Returns void

  • Start GIF animation.

    Example

    DsImageViewer.findControl("#root").startAnimation();
    

    Returns void

  • Stop GIF animation. *

    Example

    • ```javascript
    • DsImageViewer.findControl("#root").stopAnimation();
    • ```

    Returns void

  • Toggle GIF animation.

    Example

    DsImageViewer.findControl("#root").toggleAnimation();
    

    Returns void

  • Undo changes.

    Example

    if(viewer.hasUndo) {
    viewer.undo();
    }

    Returns Promise<void>

  • Redo changes.

    Example

    if(viewer.hasRedo) {
    viewer.redo();
    }

    Returns Promise<void>

  • Get event object.

    Example

    viewer.getEvent("CustomEvent").register(function(args) {
    console.log(args);
    });

    Parameters

    Returns EventFan<any>

  • Trigger event.

    Example

    // Listen CustomEvent:
    viewer.getEvent("CustomEvent").register(function(args) {
    console.log(args);
    });
    // Trigger CustomEvent:
    viewer.triggerEvent("CustomEvent", { arg1: 1, arg2: 2});

    Parameters

    Returns void

  • Modify current image data url.

    Parameters

    • dataUrl: any

    Returns Promise<void>

  • Displays a second toolbar specified by the toolbarKey argument.

    Example

    // Show the page tools toolbar
    viewer.showSecondToolbar("page-tools");

    Parameters

    • toolbarKey: SecondToolbarType

      The key identifying the specific second toolbar to show.

    Returns Promise<void>

  • Hides the second toolbar. This method deactivates any active editor mode associated with the second toolbar and then hides the toolbar itself.

    Returns

    A Promise that resolves once the second toolbar is successfully hidden.

    Example

    // Hide the second toolbar
    viewer.hideSecondToolbar();

    Example

    // Hide a specific second toolbar by passing its key
    viewer.hideSecondToolbar("page-tools");

    Parameters

    • Optional toolbarKey: SecondToolbarType

      Optional. The key identifying the specific second toolbar to hide. If provided, only hides the specified toolbar if it exists.

    Returns Promise<void>

  • Show the file open dialog where the user can select the Image file.

    Example

    viewer.openLocalFile();
    

    Returns any

  • Downloads the Image document loaded in the Viewer to the local disk.

    Deprecated

    Deprecated since v1.2.0-a6 in favor of the save method.

    Parameters

    • Optional fileName: string

      the destination file name.

    • Optional original: boolean

      Flag indicating whether to use the original image for save. Defaults to false.

    Returns void

  • Saves the Image document loaded in the Viewer to the local disk.

    Example

    // Example: Save the modified image without using specific options.
    const viewer = DsImageViewer.findControl("#root");
    viewer.save();

    Example

    // Example: Save the modified image as "image.png".
    const viewer = DsImageViewer.findControl("#root");
    viewer.save({ fileName: "image.png" });

    Example

    // Example: Download the original version of the image as "original_image.jpg".
    const viewer = DsImageViewer.findControl("#root");
    viewer.save({ fileName: "original_image.jpg", original: true });

    Example

    // Example: Save the modified image in PNG format.
    const viewer = DsImageViewer.findControl("#root");
    viewer.save({ convertToFormat: "image/png" });

    Example

    // Example: Save the modified image with a custom file name and in JPEG format.
    const viewer = DsImageViewer.findControl("#root");
    viewer.save({ fileName: "custom_name", convertToFormat: "image/jpeg" });

    Parameters

    • Optional options: string | SaveOptions

      The save options, including the destination file name and other settings.

    • Optional original: boolean

      Flag indicating whether to use the initial version of the image for save. Defaults to false.

    Returns void

  • Shows the message for the user.

    Parameters

    • message: string
    • details: string = ""
    • severity: "error" | "warn" | "info" | "debug" = "info"

    Returns void

Accessors

  • get hostElement(): Element
  • Gets the main window's host element

    Returns Element

  • get errorHandler(): ErrorHandler
  • Gets or sets callback that is invoked when an error occurs in the process of displaying the report

    Returns ErrorHandler

  • get onDocumentOpen(): EventFan<DocumentOpenedEventArgs>
  • The event indicating document was changed (new document opened, drilled or "back to parent" is issued)

    Returns EventFan<DocumentOpenedEventArgs>

  • get onDocumentViewOpen(): EventFan<DocumentViewOpenedEventArgs>
  • The event indicating document view was changed (new document opened, refreshed, toggled etc)

    Returns EventFan<DocumentViewOpenedEventArgs>

  • get onDocumentProgress(): EventFan<ProgressMessage>
  • The event indicating document load progress

    Returns EventFan<ProgressMessage>

  • get onViewerStateChange(): EventFan<ChangedEventArgs>
  • Indicates the viewer state was changed.

    Returns EventFan<ChangedEventArgs>

  • get tempOnPanelChange(): EventFan<null | string>
  • Temporary expose event, which occurs on panel change

    Returns EventFan<null | string>

  • get viewerState(): Model
  • Gets currently viewed document state

    Returns Model

  • get viewMode(): ViewMode
  • Gets or sets view mode (single page or continuous).

    Returns ViewMode

  • get zoomTarget(): ZoomTarget
  • Gets/sets target element for zoom transformation. If 'page' is set, each page will be transformed individually (default behavior). If 'viewport' is set, entire viewport element will be transformed instead. This is added to prevent issues in some specific cases, see ARJ-4340. *

    Returns ZoomTarget

  • get backgroundColor(): string
  • Gets or sets viewer background color, default value = 'transparent'

    Returns string

  • get pageDecoration(): PageDecoration
  • Gets or sets page view decoration mode.

    Returns PageDecoration

  • get document(): null | IDocumentView
  • Gets the current document

    Returns null | IDocumentView

  • get hasImage(): boolean
  • Indicates whether the viewer has opened the image.

    Example

     var hasImageFlag = viewer.hasImage;
    

    Returns boolean

  • get adaptiveNaturalSize(): { width: number; height: number }
  • Gets the active image DPI adaptive natural size. This is the image size that will be used to display the image at 100%. The adaptiveNaturalSize property is used for the actual size calculations.

    Returns { width: number; height: number }

    • width: number
    • height: number
  • get actualSize(): { width: number; height: number }
  • Gets the actual display size of the active image, including the active zoom value.

    Returns { width: number; height: number }

    • width: number
    • height: number
  • get language(): string
  • language - A property that retrieves the standardized language key based on the provided language option. The language key is determined by the options.language setting.

    Returns

    Standardized language key (e.g., 'en', 'ja').

    Returns string

  • get layers(): IImageLayer[]
  • Image layers. Used for painting.

    Returns IImageLayer[]

  • get naturalSize(): { width: number; height: number }
  • Gets the active image natural size. The natural size is the image's width/height if drawn with nothing constraining its width/height, this is the number of CSS pixels wide the image will be.

    Returns { width: number; height: number }

    • width: number
    • height: number
  • get toolbarLayout(): ImageToolbarLayout
  • Defines the layout of the toolbar.

    Description

    The full list of the viewer specific toolbar items:

    'open', '$navigation', 'navigation-auto', '$split', 'zoom', '$fullscreen', 'save', 'about'
    

    Example

    // Customize the toolbar layout:
    viewer.toolbarLayout.viewer.default = ["open", "$zoom", "$fullscreen", "save", "print", "about"];
    viewer.applyToolbarLayout();

    Returns ImageToolbarLayout

  • get undoStorage(): UndoStorage
  • Command based undo state storage.

    Example

    const isUndoInProgress = viewer.undoStorage.undoInProgress;
    

    Returns UndoStorage

  • get hasUndo(): boolean
  • Gets a value indicating whether the image viewer can undo changes.

    Example

    if(viewer.hasUndo) {
    viewer.undo();
    }

    Returns boolean

  • get hasRedo(): boolean
  • Gets a value indicating whether the image viewer can redo changes.

    Example

    if(viewer.hasRedo) {
    viewer.redo();
    }

    Returns boolean

  • get undoIndex(): number
  • Gets current undo level index.

    Example

    alert("The current Undo level index is " + viewer.undoIndex);
    

    Returns number

  • get undoCount(): number
  • Gets total undo levels count.

    Example

    alert("Undo levels count is " + viewer.undoCount);
    

    Returns number

  • get version(): string
  • Returns the current version of the DS Image viewer.

    Example

    alert("The DsImageViewer version is " + viewer.version);
    

    Returns string

  • get frameIndex(): number
  • Gets or sets the active frame index. This is applicable for multi-frame images such as TIFF and ICO.

    When setting this value, it will also be used as the initial frame index when opening a new image.

    Example

    var viewer = new DsImageViewer('#root');
    viewer.frameIndex = 9;
    viewer.open('Test.ico');

    Returns number

  • get framesCount(): number
  • Gets total frames count for the active image. Applicable for TIFF, ICO images.

    Example

    var viewer = new DsImageViewer('#root');
    viewer.onAfterOpen.register(function() {
    alert("The image opened. Total number of frames: " + viewer.framesCount);
    });
    viewer.open('Test.png');

    Returns number

  • get eventBus(): IEventBus
  • Image viewer event bus.

    Example

    viewer.eventBus.on("after-open", function(args) {
    console.log("Image opened.", args);
    });
    viewer.open('Test.png');

    Returns IEventBus

  • get onAfterOpen(): EventFan<EventArgs>
  • The event raised when the user changes the viewer theme.

    Example

    var viewer = new DsImageViewer('#root');
    viewer.onAfterOpen.register(function() {
    alert("The image opened.");
    });
    viewer.open('Test.png');

    Returns EventFan<EventArgs>

  • get onBeforeOpen(): EventFan<BeforeOpenEventArgs>
  • Occurs immediately before the image opens.

    Example

    var viewer = new DsImageViewer('#root');
    viewer.onBeforeOpen.register(function(args) {
    alert("A new image will be opened,\n payload type(binary or URL): " + args.type +",\n payload(bytes or string): " + args.payload);
    });
    viewer.open('Test.png');

    Returns EventFan<BeforeOpenEventArgs>

  • get onError(): EventFan<ErrorEventArgs>
  • The event indicating error.

    Example

    function handleError(args) {
    console.error(args);
    }
    var viewer = new DsImageViewer('#root');
    viewer.onError.register(handleError);
    viewer.open('Test.png');

    Returns EventFan<ErrorEventArgs>

  • get isAnimationStarted(): boolean
  • Gets a value indicating whether the image animation has started.

    Example

    // Toggle image animation:
    const viewer = DsImageViewer.findControl("#root");
    if(viewer.isAnimationStarted) {
    viewer.stopAnimation();
    } else {
    viewer.startAnimation();
    }

    Returns boolean

Properties

toggleSidebar: ((show?: boolean) => void)

Type declaration

    • (show?: boolean): void
    • Sets of toggles sidebar's panels visibility

      Parameters

      • Optional show: boolean

      Returns void

Constructors

  • DsImageViewer constructor.

    Parameters

    • element: string | HTMLElement

      Required. HTML element or CSS selector.

    • options: Partial<ViewerOptions> = {}

      Optional. Viewer options.

    Returns GcImageViewer