[]
GcDocs Image Viewer - v1.0.1 / GcImageViewer
GcImageViewer component. GrapeCity Documents Image Viewer (GcImageViewer) is a fast JavaScript based client-side Image Viewer that runs in all major browsers.
Example
var viewer = new GcImageViewer("#root");
ReportViewer
↳ GcImageViewer
▸ Static
findControl(selector
): undefined
| GcImageViewer
Gets the viewer instance using the host element or host element selector
Example
var viewer = GcImageViewer.findControl("#root");
Name | Type |
---|---|
selector |
string | HTMLElement |
undefined
| GcImageViewer
▸ executeTask(task
, settings?
): Promise
<void
>
Starts long-running operation and displays progress window while operation is running.
Name | Type |
---|---|
task |
(callbacks : TaskCallbacks ) => Promise <void > |
settings? |
TaskSettings |
Promise
<void
>
ReportViewer.executeTask
▸ showPanel(panelKey
, visible?
): void
Updates the panel visibility.
Name | Type |
---|---|
panelKey |
PanelHandle |
visible? |
boolean |
void
ReportViewer.showPanel
▸ updatePanel(panelKey
, settings
): void
Updates panel settings such as visibility, label or "enabled" status.
Name | Type |
---|---|
panelKey |
PanelHandle |
settings |
Partial <PanelSettings > |
void
ReportViewer.updatePanel
▸ getPanelState(panelKey
): null
| PanelSettings
Gets the current panel state.
Name | Type |
---|---|
panelKey |
PanelHandle |
null
| PanelSettings
ReportViewer.getPanelState
▸ layoutPanels(layout
): void
Orders and filters panel items. '*' indicates "the rest of panels". 'sep'/'separator' indicated menu separator.
Name | Type |
---|---|
layout |
string [] |
void
ReportViewer.layoutPanels
▸ setActiveTopPanel(id
): void
Updates activeTopPanelId for to show/hide panel with setting.location = 'top' (id = null to hide panel)
Name | Type |
---|---|
id |
null | string |
void
ReportViewer.setActiveTopPanel
▸ setActiveBottomPanel(id
): void
Updates activeBottomPanelId for to show/hide panel with setting.location = 'bottom' (id = null to hide panel)
Name | Type |
---|---|
id |
null | string |
void
ReportViewer.setActiveBottomPanel
▸ resetDocument(): Promise
<void
>
Resets report and cancel current session if any.
Promise
<void
>
ReportViewer.resetDocument
▸ load(moniker
, token?
): Promise
<LoadResult
>
Loads the report (no UI), so caller has to process load result and report error if any.
Name | Type |
---|---|
moniker |
DocumentMoniker |
token? |
CancellationToken |
Promise
<LoadResult
>
ReportViewer.load
▸ toggleFullscreen(fullscreen?
): void
Toggle full screen mode.
Name | Type |
---|---|
fullscreen? |
boolean |
void
ReportViewer.toggleFullscreen
▸ toggleToolbar(show?
): void
Toggle toolbar visibility.
Name | Type |
---|---|
show? |
boolean |
void
ReportViewer.toggleToolbar
▸ applyOptions(): void
Call this method in order to apply changed options.
Example
viewer.applyOptions();
void
▸ applyToolbarLayout(): void
Call this method in order to apply changes in @see:toolbarLayout.
Example
viewer.toolbarLayout.viewer.default = ["open", "download"];
viewer.applyToolbarLayout();
Example
var viewer = new GcImageViewer(document.querySelector("#viewer"));
viewer.addDefaultPanels();
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();
void
▸ addPlugin(plugin
): void
Add plug-in instance which is used to add new functionality to the GcImageViewer.
Example
var viewer = new GcImageViewer("#root");
var rotationPlugin = new RotationPlugin();
viewer.addPlugin(rotationPlugin);
Name | Type |
---|---|
plugin |
IViewerPlugin |
void
▸ removePlugin(pluginId
): void
Remove plug-in instance from the GcImageViewer.
Example
var viewer = new GcImageViewer("#root");
var rotationPlugin = new RotationPlugin();
viewer.addPlugin(rotationPlugin);
viewer.removePlugin(rotationPlugin.id);
Name | Type | Description |
---|---|---|
pluginId |
string | IViewerPlugin |
Plugin id or plugin instance. |
void
▸ findPlugin(pluginId
): null
| IViewerPlugin
Finds a viewer plugin by its id.
Example
// find imageFilters plugin:
var imageFilters = viewer.findPlugin("imageFilters");
// find pageTools plugin:
var pageTools = viewer.findPlugin("pageTools");
Name | Type |
---|---|
pluginId |
string |
null
| IViewerPlugin
▸ removePlugins(): void
Remove all plug-ins.
Example
viewer.removePlugins();
void
▸ clearUndo(): void
Clear undo storage.
void
▸ executeCommand(command
): Promise
<void
>
Execute a new command.
Name | Type | Description |
---|---|---|
command |
UndoCommandSupport |
Instance of a CommandBase. |
Promise
<void
>
▸ newImage(options?
): Promise
<any
>
Create new empty image.
Example
await viewer.newImage({ width: 300, height: 300, fileName: "myImage.png" });
Name | Type |
---|---|
options? |
{ width? : number ; height? : number } & OpenParameters |
Promise
<any
>
▸ open(file?
, openParameters?
): Promise
<any
>
Open Image document.
Example
viewer.open("Images/HelloWorld.png");
Name | Type | Description |
---|---|---|
file? |
any |
URL to Image document(string) or binary data(Typed array - Uint8Array). |
openParameters? |
GcImageFormatName | GcImageFormat | OpenParameters |
Loading parameters object. |
Promise
<any
>
ReportViewer.open
▸ dispose(): void
Use this method to close and release resources occupied by the GcImageViewer.
void
ReportViewer.dispose
▸ startAnimation(): void
Start GIF animation.
Example
GcImageViewer.findControl("#root").startAnimation();
void
▸ stopAnimation(): void
Stop GIF animation. *
Example
void
▸ toggleAnimation(): void
Toggle GIF animation.
Example
GcImageViewer.findControl("#root").toggleAnimation();
void
▸ undo(): void
Undo changes.
Example
if(viewer.hasUndo) {
viewer.undo();
}
void
▸ redo(): void
Redo changes.
Example
if(viewer.hasRedo) {
viewer.redo();
}
void
▸ getEvent(eventName
): EventFan
<any
>
Get event object.
Example
viewer.getEvent("CustomEvent").register(function(args) {
console.log(args);
});
Name | Type |
---|---|
eventName |
EventName |
EventFan
<any
>
▸ triggerEvent(eventName
, args?
): void
Trigger event.
Example
// Listen CustomEvent:
viewer.getEvent("CustomEvent").register(function(args) {
console.log(args);
});
// Trigger CustomEvent:
viewer.triggerEvent("CustomEvent", { arg1: 1, arg2: 2});
Name | Type |
---|---|
eventName |
EventName |
args? |
any |
void
▸ getOriginalImageDataUrl(): string
Get unmodified current image data url.
string
▸ getImageDataUrl(): string
Get current image data url.
string
▸ setImageDataUrl(dataUrl
): Promise
<void
>
Modify current image data url.
Name | Type |
---|---|
dataUrl |
any |
Promise
<void
>
▸ showSecondToolbar(toolbarKey
): Promise
<void
>
Show a second toolbar with a key specified by the toolbarKey argument.
Example
// Show page tools bar.
viewer.showSecondToolbar("page-tools");
Name | Type |
---|---|
toolbarKey |
string |
Promise
<void
>
▸ openLocalFile(): any
Show the file open dialog where the user can select the Image file.
Example
viewer.openLocalFile();
any
▸ download(fileName?
, getInitialVersion?
): void
Downloads the Image document loaded in the Viewer to the local disk.
Example
// Download modified image.
viewer.download("image.png");
Example
// Download initial image.
viewer.download("image.png", true);
Name | Type | Description |
---|---|---|
fileName? |
string |
the destination file name. |
getInitialVersion? |
boolean |
- |
void
▸ showMessage(message
, details?
, severity?
): void
Shows the message for the user.
Name | Type | Default value |
---|---|---|
message |
string |
undefined |
details |
string |
"" |
severity |
"error" | "debug" | "info" | "warn" |
"info" |
void
• get
hostElement(): Element
Gets the main window's host element
Element
ReportViewer.hostElement
• get
errorHandler(): ErrorHandler
Gets or sets callback that is invoked when an error occurs in the process of displaying the report
ErrorHandler
ReportViewer.errorHandler
• get
onViewerStateChange(): EventFan
<ChangedEventArgs
>
Indicates the viewer state was changed.
EventFan
<ChangedEventArgs
>
ReportViewer.onViewerStateChange
• get
toolbar(): Toolbar
Gets toolbar API
Toolbar
ReportViewer.toolbar
• get
viewerState(): Model
Gets currently viewed document state
Model
ReportViewer.viewerState
• get
zoom(): ZoomSettings
Zoom settings.
Example
// Set zoom to 50%.
viewer.zoom = { mode: 0, factor: 0.5 };
Example
// Zoom mode - fit image width
viewer.zoom = { mode: 1 };
Example
// Zoom mode - fit whole image
viewer.zoom = { mode: 2 };
ZoomSettings
ReportViewer.zoom
• get
isFullscreen(): boolean
Gets a value indicating full screen mode.
boolean
ReportViewer.isFullscreen
• get
isToolbarHidden(): boolean
Gets a value indicating whether the toolbar is hidden.
boolean
ReportViewer.isToolbarHidden
• get
imageFormat(): GcImageFormat
Format type of the active image. Available image formats are: 1 = JPEG , 2 = PNG, 3 = TIFF, 4 = GIF, 5 = BMP, 6 = ICO, 7 = SVG, 8 = WEBP.
• get
hasImage(): boolean
Indicates whether the viewer has opened the image.
Example
<script>
var hasImageFlag = viewer.hasImage;
</script>
boolean
• get
adaptiveNaturalSize(): Object
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.
Object
Name | Type |
---|---|
width |
number |
height |
number |
• get
actualSize(): Object
Gets the actual display size of the active image, including the active zoom value.
Object
Name | Type |
---|---|
width |
number |
height |
number |
• get
naturalSize(): Object
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.
Object
Name | Type |
---|---|
width |
number |
height |
number |
• get
openParameters(): undefined
| OpenParameters
The Open parameters that were used to open an image.
undefined
| OpenParameters
• get
options(): Partial
<ViewerOptions
>
Viewer options
Partial
<ViewerOptions
>
• get
toolbarLayout(): ImageToolbarLayout
Defines the layout of the toolbar.
Description
The full list of the viewer specific toolbar items:
'open', '$navigation', '$split', 'zoom', '$fullscreen', 'download', 'about'
Example
// Customize the toolbar layout:
viewer.toolbarLayout.viewer.default = ["open", "$zoom", "$fullscreen", "download", "print", "about"];
viewer.applyToolbarLayout();
• get
undoStorage(): UndoStorage
Command based undo state storage.
Example
const isUndoInProgress = viewer.undoStorage.undoInProgress;
• get
hasUndo(): boolean
Gets a value indicating whether the image viewer can undo changes.
Example
if(viewer.hasUndo) {
viewer.undo();
}
boolean
• get
hasRedo(): boolean
Gets a value indicating whether the image viewer can redo changes.
Example
if(viewer.hasRedo) {
viewer.redo();
}
boolean
• get
undoIndex(): number
Gets current undo level index.
Example
alert("The current Undo level index is " + viewer.undoIndex);
number
• get
undoCount(): number
Gets total undo levels count.
Example
alert("Undo levels count is " + viewer.undoCount);
number
• get
version(): string
Returns the current version of the GcDocs Image viewer.
Example
alert("The GcImageViewer version is " + viewer.version);
string
• get
frameIndex(): number
Gets/sets the active frame index. Applicable for TIFF, ICO images.
Example
var viewer = new GcImageViewer('#root');
viewer.onAfterOpen.register(function() {
// Navigate frame with index 9:
viewer.frameIndex = 9;
});
viewer.open('Test.ico', { imageFormat: 6 });
number
• get
framesCount(): number
Gets total frames count for the active image. Applicable for TIFF, ICO images.
Example
var viewer = new GcImageViewer('#root');
viewer.onAfterOpen.register(function() {
alert("The image opened. Total number of frames: " + viewer.framesCount);
});
viewer.open('Test.png');
number
• get
eventBus(): EventBus
Image viewer event bus.
Example
viewer.eventBus.on("after-open", function(args) {
console.log("Image opened.", args);
});
viewer.open('Test.png');
• get
onAfterOpen(): EventFan
<EventArgs
>
The event raised when the user changes the viewer theme.
Example
var viewer = new GcImageViewer('#root');
viewer.onAfterOpen.register(function() {
alert("The image opened.");
});
viewer.open('Test.png');
EventFan
<EventArgs
>
• get
onBeforeOpen(): EventFan
<BeforeOpenEventArgs
>
Occurs immediately before the document opens.
Example
var viewer = new GcImageViewer('#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');
EventFan
<BeforeOpenEventArgs
>
• get
onError(): EventFan
<ErrorEventArgs
>
The event indicating error.
Example
function handleError(args) {
console.error(args);
}
var viewer = new GcImageViewer('#root');
viewer.onError.register(handleError);
viewer.open('Test.png');
EventFan
<ErrorEventArgs
>
• get
onImagePaint(): EventFan
<ImagePaintEventArgs
>
The event raised when appearance image element changed.
EventFan
<ImagePaintEventArgs
>
• get
isAnimationStarted(): boolean
Gets a value indicating whether the image animation has started.
Example
// Toggle image animation:
const viewer = GcImageViewer.findControl("#root");
if(viewer.isAnimationStarted) {
viewer.stopAnimation();
} else {
viewer.startAnimation();
}
boolean
• toggleSidebar: (show?
: boolean
) => void
▸ (show?
): void
Sets of toggles sidebar's panels visibility
Name | Type |
---|---|
show? |
boolean |
void
ReportViewer.toggleSidebar
• new GcImageViewer(element
, options?
)
GcImageViewer constructor.
Name | Type | Description |
---|---|---|
element |
string | HTMLElement |
Required. HTML element or CSS selector. |
options |
Partial <ViewerOptions > |
Optional. Viewer options. |
ReportViewer.constructor