ImageGear .NET - Updated
IPCC.ViewerControl
API Reference > ViewerControl API > IPCC.ViewerControl

Class: ViewerControl

IPCC.ViewerControl(element, options)

The `ViewerControl` is a document viewer without any menus, buttons, dialogs, etc. The UI only consists of a page list, which allows a user to scroll through the pages of a document. It is the most basic viewer which shows a document. It can be used alone, or it can be augmented with UI elements (chrome) to expose more functionality to the end user. Our out-of-the-box HTML5 viewer uses the `ViewerControl` to build a desktop and mobile ready viewer, with extensive UI chrome and a responsive design. The `ViewerControl` has an API, which covers the full set of viewer functionality. Code that directly uses the ViewerControl will typically create UI elements - buttons, menus, and inputs - for the end user to interact with. These UI elements will be hooked up to call the `ViewerControl` API when the user interacts with the UI elements (e.g. on button click, call `.changeToNextPage()`). The `ViewerControl` also permits mouse and touch interaction. The behavior of the mouse tool or touch is set using the API method IPCC.ViewerControl#setCurrentMouseTool. Once the tool is set, the user can interact with the viewer using the mouse tool or touch.

Constructor

new ViewerControl(element, options)

Creates a new `IPCC.ViewerControl` object.
Parameters:
Name Type Description
element HTMLDivElement Embed the ViewerControl in this element.
options IPCC.ViewerControl~ViewerControlOptions Specify options for the ViewerControl object. Some options are required.

Members

(readonly) atMaxScale :boolean

_An ECMA 5 accessor property that is defined only in browsers supporting ECMA 5. This property is not available in the older browsers like IE8._ It checks whether the viewer is currently at the maximum zoom level.
Type:
  • boolean
See:

(readonly) atMinScale :boolean

_An ECMA 5 accessor property that is defined only in browsers supporting ECMA 5. This property is not available in the older browsers like IE8._ It checks whether the viewer is currently at the minimum zoom level.
Type:
  • boolean
See:

currentMouseTool :string

_An ECMA 5 accessor property that is defined only in browsers supporting ECMA 5. This property is not available in the older browsers like IE8._ Gets and sets the current mouse tool of the viewer by name.
Type:
  • string
See:

(readonly) pageCount :number

_An ECMA 5 accessor property that is defined only in browsers supporting ECMA 5. This property is not available in the older browsers like IE8._ Gets the document page count.
Type:
  • number
See:

pageNumber :number

_An ECMA 5 accessor property that is defined only in browsers supporting ECMA 5. This property is not available in the older browsers like IE8._ Gets and sets the current page of the viewer to the specified page number in the document. Setting the page number to a value other than the current page number will cause the viewer to navigate to the page number provided in the parameter.
Type:
  • number
See:

scaleFactor :number

_An ECMA 5 accessor property that is defined only in browsers supporting ECMA 5. This property is not available in the older browsers like IE8._ Gets or sets the scale factor to use in the viewer, with 1 being 100% zoom.
Type:
  • number
See:

viewMode :IPCC.ViewMode

_An ECMA 5 accessor property that is defined only in browsers supporting ECMA 5. This property is not available in the older browsers like IE8._ Gets or sets the view mode. This defines how the document pages will be scaled, based on the values of the IPCC.ViewMode enumerable values.
Type:
See:

Methods

addMark(pageNumber, markType) → {IPCC.Mark}

Creates a new mark of a specific type and adds to the specified page.
Parameters:
Name Type Description
pageNumber number Indicates the page to which to add the mark.
markType IPCC.Mark.Type | string Indicates the type of mark being added
Throws:
  • If IPCC.EventType.ViewerReady event was not fired prior to using this method.
    Type
    Error
  • If an invalid `pageNumber` is provided.
    Type
    Error
Returns:
The new mark.
Type
IPCC.Mark
Example
viewerControl.addMark(1, "LineAnnotation");

changeToFirstPage() → {IPCC.ViewerControl}

Sets the current page of the viewer to the first page of the document. **Note:** Does nothing if the current page is the first page of the document.
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
viewerControl.changeToFirstPage();

changeToLastPage() → {IPCC.ViewerControl}

Sets the current page of the viewer to the last known page of the document. **Note:** Does nothing if the current page is the last known page of the document.
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
viewerControl.changeToLastPage();

changeToNextPage() → {IPCC.ViewerControl}

Sets the current page of the viewer to the next page of the document. **Note:** Does nothing if the current page is the last known page of the document.
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
viewerControl.changeToNextPage();

changeToPrevPage() → {IPCC.ViewerControl}

Sets the current page of the viewer to the previous page of the document.
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
viewerControl.changeToPrevPage();

convertPageToWindowCoordinates(pageNumber, points) → {Array.<Object>|Object}

Converts page-based coordinates to the current window coordinates. This allows passing in a coordinate point or an array of points as used in the `ViewerControl` API, in order to get the position of that point or points relative to the window.
Parameters:
Name Type Description
pageNumber number A known page number to the viewer.
points Array.<Object> | Object A point or array of points in page coordinates. Each point will have the following properties:
Properties
Name Type Description
x number the x page coordinate
y number the y page coordinate
Throws:
  • If the IPCC.EventType.ViewerReady event has not fired prior to calling this method.
    Type
    Error
  • If `pageNumber` is not a currently known page.
    Type
    Error
  • If any of the points do not have a valid `x` and `y` numeric parameters.
    Type
    Error
Returns:
A window point or an array of window points, depending on how the method was called. These points will be in the same order as the points passed into the function. Each window point will have the following parameters: - `clientX` {number} The x window coordinate. - `clientY` {number} The y window coordinate.
Type
Array.<Object> | Object

copyMarks(marks) → {Array.<IPCC.Mark>}

Makes a copy of the specified marks.
Parameters:
Name Type Description
marks Array.<IPCC.Mark> An array of marks to copy.
Throws:
If marks is not an array of marks known to the viewer.
Type
Error
Returns:
An array of the copied marks.
Type
Array.<IPCC.Mark>
Example
// Make a copy of the selected marks.
markupLayer1.copyMarks(viewerControl.getSelectedMarks());

deleteAllMarks() → {IPCC.ViewerControl}

Deletes all marks in all the pages of the document.
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
viewerControl.deleteAllMarks();

deleteMarks(marks) → {IPCC.ViewerControl}

Deletes the specified marks.
Parameters:
Name Type Description
marks Array.<IPCC.Mark> An Array of objects of type IPCC.Mark.
Throws:
  • If IPCC.EventType.ViewerReady event was not fired prior to using this method.
    Type
    Error
  • If any of the marks passed in are not valid objects of the type IPCC.Mark.
    Type
    Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
// delete all selected marks
viewerControl.deleteMarks(viewer.getSelectedMarks());

deselectAllMarks() → {IPCC.ViewerControl}

Deselects all previously selected marks.
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
viewerControl.deselectAllMarks();

deselectMarks(marks) → {IPCC.ViewerControl}

Deselects the marks provided in the parameter array object.
Parameters:
Name Type Description
marks Array.<IPCC.Mark> An array of IPCC.Mark objects that exist in the document and need to be deselected.
Throws:
  • If IPCC.EventType.ViewerReady event was not fired prior to calling this method.
    Type
    Error
  • If any of the mark objects are not valid IPCC.Mark objects, the id of the mark provided does not match the id of mark loaded in the viewer, or the mark provided was not previously added to the document pages.
    Type
    Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
// deselect all marks with an odd-number ID
viewerControl.getSelectedMarks().forEach(function(mark){
    var arr = [];
    if (+mark.getId() % 2) arr.push(mark);
    viewerControl.deselectMarks(arr);
});

destroy()

Closes the `ViewerControl` and cleans up its resources. After this action, a new viewer can be created in its place. _Note: If the viewer was created using the jQuery plugin (IPCC.Viewer), use the IPCC.Viewer.destroy method instead._
Example
var element = document.querySelector('#mydiv');
var viewerControl = new IPCC.ViewerControl(element, options);

viewerControl.destroy();

enterTextMarkEditingMode(mark) → {IPCC.ViewerControl}

Puts a displayed IPCC.Mark object of type TextAnnotation into editing mode. In editing mode, a text input or text box will be drawn for the mark and the input will have focus. When in editing mode, the end user type to modify the text of the mark. All marks other than the specified mark will be taken out of text mark editing mode. Note that if the mark is not on a page that is currently displayed, then this method may have no perceived effect. The act of changing pages to bring the off screen page into view would take the focus off of the mark that is in editing mode.
Parameters:
Name Type Description
mark IPCC.Mark | null | undefined A IPCC.Mark object that will be put in editing mode. If a value of `null` or `undefined` is given, then **all** marks will be taken out of text mark editing mode.
Throws:
  • IPCC.Error If the IPCC.EventType.ViewerReady event was not fired prior to calling this method.
  • IPCC.Error If `mark` is not a valid IPCC.Mark object or the mark provided is not currently on the document.
  • IPCC.Error If `mark` is not of type TextAnnotation.
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
// Add a mark
var myMark = viewerControl.addMark(4, IPCC.Mark.Type.TextAnnotation)
    .setRectangle({
        x: 0,
        y: 600,
        width: 500,
        height: 100
    });

// Put the mark in editing mode and scroll to the mark.
viewerControl.enterTextMarkEditingMode(myMark);

fitContent(fitType) → {IPCC.ViewerControl}

Changes the scaling (zoom) of the document to fit the content in the viewer. How the content is fit in the viewer is based on the specified by the values in the IPCC.FitType enumerable.
Parameters:
Name Type Description
fitType string Specifies how the content will be scaled to fit in the viewer.
See:
  • IPCC.FitType for a list of possible FitType values and their descriptions.
Throws:
  • If IPCC.EventType.ViewerReady event was not fired prior to using this method.
    Type
    Error
  • If the value of `fitType` is unknown.
    Type
    Error
  • If the view mode is set to `"EqualFitPages"` or `"EqualWidthPages"`, and the value of `fitType` is `"ActualSize"`. Instead, pass a value of 1 to the IPCC.ViewerControl#setScaleFactor method to scale the first page to actual size.
    Type
    Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
// Explicitly specify the fit type
viewerControl.fitContent("FullWidth");

// or use the enumeration
viewerControl.fitContent(IPCC.FitType.FullWidth);

getActiveMarkupLayer() → {IPCC.MarkupLayer}

Gets the viewer control's active markup layer.
Returns:
The viewer control's active markup layer.
Type
IPCC.MarkupLayer
Example
var activeMarkupLayer = viewerControl.getActiveMarkupLayer();

getAllMarks() → {Array.<IPCC.Mark>}

Gets all marks.
Returns:
An array of IPCC.Mark objects. **Note:** Returns an empty array if the viewer has not been initialized.
Type
Array.<IPCC.Mark>
Example
var allMarks = viewer.getAllMarks();

getAtMaxScale() → {boolean}

Gets a value that indicates whether the viewer is currently at the maximum scale factor. As long as this value is `true`, the `ViewerControl` do nothing if asked to zoom in any further. This method determines the value each time, and will be affected by the following: 1. The viewer scale changes due to `zoomIn`, `zoomOut`, or `fitContent`. 2. The window resizes. 3. The div that holds the viewer control is resized.
See:
Throws:
If the IPCC.EventType.ViewerReady event was not fired prior to using this method.
Type
Error
Returns:
A value that indicates whether the viewer is currently at maximum zoom.
Type
boolean
Examples
// Check for change after the viewer scale changes
viewerControl.on(IPCC.EventType.ScaleChanged, function(ev){
    var atMax = viewer.getAtMaxScale();
}
// Check for change when the window resizes (using jQuery)
$(window).resize(function() {
    var atMax = viewer.getAtMaxScale();
});

getAtMinScale() → {boolean}

Gets a value that indicates whether the viewer is currently at the minimum scale factor. As long as this value is `true`, the `ViewerControl` do nothing if asked to zoom out any further. This method determines the value each time, and will be affected by the following: 1. The viewer scale changes due to `zoomIn`, `zoomOut`, or `fitContent`. 2. The window resizes. 3. The div that holds the viewer control is resized.
See:
Throws:
If the IPCC.EventType.ViewerReady event was not fired prior to using this method.
Type
Error
Returns:
A value that indicates whether the viewer is currently at minimum zoom.
Type
boolean
Examples
// Check for change after the viewer scale changes
viewerControl.on(IPCC.EventType.ScaleChanged, function(ev){
    var atMax = viewer.getAtMinScale();
}
// Check for change when the window resizes (using jQuery)
$(window).resize(function() {
    var atMax = viewer.getAtMinScale();
});

getCharacterIndex(sortableObject) → {Number}

Returns the index of the character at the location of the specified object. If there is no character at the location, the index of the character before the location (based on the closest line of text) is returned.
Parameters:
Name Type Description
sortableObject IPCC.Mark | Object A mark or an object containing pageNumber, x, and y values.
Throws:
  • If IPCC.EventType.ViewerReady event was not fired prior to using this method.
    Type
    Error
  • If sortableObject is not a valid IPCC.Mark or if it is not an Object with valid pageNumber, x, and y values. When specifying a pageNumber greater than 1, this method requires that the PageCountReady event has been triggered, otherwise an error is thrown.
    Type
    Error
Returns:
The text index at or before the position of the specified object.
Type
Number
Example
// get the first selected Mark object
var theFirstMark = viewerControl.getSelectedMarks()[0];

// get the sort index
if (theFirstMark) var firstMarkSortIndex = viewerControl.getCharacterIndex(theFirstMark);

getCurrentMouseTool() → {string}

Gets the current mouse tool of the viewer.
See:
Returns:
A value indicating the name of the current mouse tool.
Type
string
Example
// get the current mouse tool name
var mouseToolName = viewerControl.getCurrentMouseTool();

// get the actual MouseTool object
var mouseToolObject = IPCC.MouseTools.getMouseTool(mouseToolName);

getGamma() → {Number}

Gets the gamma factor for the document.
Returns:
The current gamma factor for the document.
Type
Number
Example
var gamma = viewerControl.getGamma();

getMarkById(markId) → {IPCC.Mark}

Gets the specified mark.
Parameters:
Name Type Description
markId number The ID of the mark to retrieve.
Returns:
The mark that corresponds to the specified ID.
Type
IPCC.Mark
Example
var mark = viewer.getMarkById(1);

getMarksByType(markType) → {Array.<IPCC.Mark>}

Get marks by type.
Parameters:
Name Type Description
markType IPCC.Mark.Type | string The mark type being requested. **Note:** Returns an empty array if the viewer has not been initialized.
See:
Throws:
If the parameter markType is an invalid mark type.
Type
Error
Returns:
An array of IPCC.Mark objects of the requested type.
Type
Array.<IPCC.Mark>
Example
var marksByType = viewer.getMarksByType(markType);

getMarkupLayerCollection() → {IPCC.MarkupLayerCollection}

Gets the viewer control's markup layer collection.
Returns:
The viewer control's markup layer collection.
Type
IPCC.MarkupLayerCollection
Example
var markupLayerCollection = viewerControl.getMarkupLayerCollection();

getMaxScaleFactor() → {number}

Gets the maximum scale limit.
Throws:
If the IPCC.EventType.ViewerReady event was not fired prior to calling this method.
Type
Error
Returns:
A number indicating the maximum limit at which the document can be scaled.
Type
number
Example
var maxScaleFactor = viewerControl.getMaxScaleFactor();
viewerControl.setScaleFactor(maxScaleFactor); // Zoom in to the maximum scale limit.

getMinScaleFactor() → {number}

Gets the minimum scale limit.
Throws:
If the IPCC.EventType.ViewerReady event was not fired prior to calling this method.
Type
Error
Returns:
A number indicating the minimum limit at which the document can be scaled.
Type
number
Example
var minScaleFactor = viewerControl.getMinScaleFactor();
viewerControl.setScaleFactor(minScaleFactor); // Zoom out to the minimum scale limit.

getPageCount() → {number}

Gets the known page count of the current document. This value is updated when the viewer gets the page count or estimated page count from the server. Subscribe to the IPCC.EventType.PageCountReady and IPCC.EventType.EstimatedPageCountReady events to be notified when the viewer gets the page count from the server. The initial value is 1, before any page count event.
See:
Returns:
The known page count.
Type
number
Example
// First, create the pccViewer.
var viewerControl = $("#viewer").pccViewer(viewerOptions).viewerControl;

function pageCountReadyHandler(event) {
    // The page count has now been determined.
    var pageCount = viewer.getPageCount();
    alert("Number of pages = " + pageCount);

    // Now, unsubscribe from the event.
    viewerControl.off("PageCountReady", pageCountReadyHandler);
}

// Subscribe to the PageCountReady event exposed by the API
viewerControl.on("PageCountReady", pageCountReadyHandler);

getPageLayout() → {IPCC.PageLayout}

Gets the page layout. This defines how the document pages will be arranged, based on the values of the IPCC.PageLayout enumeration.
See:
Returns:
A value indicating the page layout.
Type
IPCC.PageLayout
Example
var pageLayout = viewerControl.getPageLayout();

getPageNumber() → {number}

Gets the current page number of the viewer. This is a 1-based value, so the first page of a document is 1.
See:
Returns:
The current page of the viewer. **Note:** A value of 1 is returned before page count is available.
Type
number
Example
var currentPageNumber = viewerControl.getPageNumber();

getPageRotation(pageNumber) → {number}

gets the page rotation value for the specified page number.
Parameters:
Name Type Description
pageNumber number | string This is an optional parameter. A 1-based page number of the page. An optional string representation of a valid number is also accepted as a parameter. If this parameter is not provided, the implied pageNumber will be the currentPage.
Throws:
  • If the IPCC.EventType.ViewerReady event was not fired prior to using this method.
    Type
    Error
  • If the provided optional parameter `pageNumber` is less than 1 or greater than the value returned by IPCC.ViewerControl#getPageCount.
    Type
    Error
  • If the provided optional parameter `pageNumber` is not a number or a string representation of a number.
    Type
    Error
  • If the provided optional parameter `pageNumber` is not an integer page number.
    Type
    Error
Returns:
The rotation amount in degrees clockwise.
Type
number
Example
// first create the pccViewer : Note: if the viewer object has already been created, do not re-create it.
var viewerControl = $("#viewer").pccViewer(viewerOptions).viewerControl;

var pageNumber = 2;
var rotationAngle = viewerControl.getPageRotation(pageNumber);

getSavedMarkupNames()

Gets a list of all saved markups from the server for the current document. If unable to retrieve markup list from server, then the returned `IPCC.Promise` object is rejected with the reason set to a `IPCC.Error` object with its code property set to MarkupListFail. If AJAX is not supported, then the returned `IPCC.Promise` object is rejected with the reason set to a `IPCC.Error` object with its code property set to AjaxUnsupported. If a server error is encountered, then the returned `IPCC.Promise` object is rejected with the reason set to a `IPCC.Error` object with its code property set to Error. The `IPCC.Promise~onFulfilled` function gets passed an `Array` of `Objects`. Each object will have a `name` property, which is a string representation of the name used to save the markup.
Returns:
IPCC.Promise A `IPCC.Promise` object.
Example
viewerControl.getSavedMarkupNames().then(
    function onSuccess(markupNameObjects) {
        var namesArray = [];
        for (var i = 0; i < markupNames.length; i++) {
            namesArray.push(markupNames[i].name);
        }
        alert(namesArray.join(', ');
    },
    function onFailure(error) {
        alert((error.message ? error.message : error));
    }
);

getScaleFactor() → {number}

Gets the scale factor of the viewer.
See:
Returns:
A value indicating the scale factor to use in the viewer, with 1 being 100% zoom. For `"Document"` and '"SinglePage"' view mode, the scale factor represents the amount that each page in the document is scaled. For `"EqualFitPages"` view mode, the scale factor represents the amount that the first page of the document is scaled.
Type
number
Example
var scaleFactor = viewerControl.getScaleFactor();

getSelectedMarks() → {Array.<IPCC.Mark>}

Obtains all the selected marks in the currently loaded document. If none of the marks are selected or if the document does not contain any marks then the returned array will be empty.
Returns:
An array of selected IPCC.Mark objects.
Type
Array.<IPCC.Mark>
Example
var selectedMarks = viewerControl.getSelectedMarks();

if (selectedMarks.length) alert(selectedMarks.length + " marks are currently selected");
else alert("No marks are currently selected");

getSharpening() → {Number}

gets the sharpening factor for the document.
Returns:
the current sharpening factor for the document.
Type
Number
Example
var sharpening = viewerControl.getSharpening();

getSvgLineWidthMultiplier() → {Number}

Gets the current multiplier used to adjust SVG line widths in the document.
Returns:
The current svg line-width multiplier for the document.
Type
Number
Example
var svgLineWidthMultiplier = viewerControl.getSvgLineWidthMultiplier();

getViewMode() → {IPCC.ViewMode}

Gets the view mode. This defines how the document pages will be scaled, based on the values of the IPCC.ViewMode enumerable values.
See:
Returns:
A value indicating the view mode.
Type
IPCC.ViewMode
Example
var viewMode = viewerControl.getViewMode();

hideMarks(marks) → {IPCC.ViewerControl}

Hides the specified marks.
Parameters:
Name Type Description
marks Array.<IPCC.Mark> An Array of objects of type IPCC.Mark.
Throws:
  • If IPCC.EventType.ViewerReady event was not fired prior to using this method.
    Type
    Error
  • If any of the marks passed in are not valid objects of the type IPCC.Mark.
    Type
    Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
// hides all selected marks
viewerControl.hideMarks(viewer.getSelectedMarks());

loadMarkup(recordName, retainExistingMarksopt, markupLayeropt)

Loads the markup with the specified name from the server. This returns a `IPCC.Promise` object. If the parameter `recordName` is invalid, then the `IPCC.Promise` object that is returned will be rejected with the reason set to a `IPCC.Error` object with its code property set to InvalidAnnotationRecord. If the optional parameters `retainExistingMarks` or `markupLayer` are specified but invalid, then the `IPCC.Promise` object that is returned will be rejected with the reason set to a `IPCC.Error' object. If a server error is encountered, then the returned `IPCC.Promise` object is rejected with the reason set to a `IPCC.Error` object with its code property set to Error. If AJAX is not supported, then the returned `IPCC.Promise` object is rejected with the reason set to a `IPCC.Error` object with its code property set to AjaxUnsupported. **Note:** Any existing marks in the document are removed before marks are loaded.
Parameters:
Name Type Attributes Default Description
recordName string Name of the annotation record to be loaded.
retainExistingMarks boolean <optional>
true If true, retains the existing marks.
markupLayer IPCC.MarkupLayer <optional>
If set to a valid markup layer, the marks are added to the specified markup layer. If not set, the marks are added to the currently active markup layer. Otherwise, clears the existing marks before loading new marks.
See:
Returns:
IPCC.Promise a Promise object.
Example
viewerControl.loadMarkup("mymarkup").then(
function onResolved() {
    // update the UI, or whatever... because the markup loaded successfully
},
function onRejected(error) {
    alert("loading failed! " + (error.message ? error.message : error));
});

loadMarkupLayers(layerRecordIds)

Load markup layer records from the server. This method loads one or more layers from the server asynchronously, and returns a `Promise` to resolve the request. The [`onFulfilled`]`IPCC.Promise~onFulfilled` callback will receive an object containing IPCC.MarkupLayer objects representing the loaded layers. The [`onRejected`]`IPCC.Promise~onRejected` callback will receive an `IPCC.Error` object defining why the load function failed.
Parameters:
Name Type Description
layerRecordIds string | Array.<string> A string or an array of layer record IDs.
Returns:
IPCC.Promise A `Promise` object.
Example
// load a layer

viewerControl.loadMarkupLayers('abc123').then(
    function onSuccess(layers){
        console.log('layer saved successfully', layers[0].getId());
    },
    function onFailure(reason){
        console.log('layer failed to load:', reason.code, reason.message);
    }
);

moveMarkBackward(mark) → {IPCC.ViewerControl}

Moves the specified mark one slot backward from its position in the internal `z-order`. When the marks overlap, marks that are higher in this internal `z-order` are drawn over the marks that are lower.
Parameters:
Name Type Description
mark IPCC.Mark The mark being moved.
Throws:
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
// get the first selected Mark object
var theFirstMark = viewerControl.getSelectedMarks()[0];

// move it backward
if (theFirstMark) viewerControl.moveMarkBackward(theFirstMark);

moveMarkForward(mark) → {IPCC.ViewerControl}

Moves the specified mark one slot toward the top of the internal `z-order`. When the marks overlap, marks that are higher in this internal `z-order` are drawn over the marks that are lower.
Parameters:
Name Type Description
mark IPCC.Mark The mark being moved.
Throws:
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
// get the first selected Mark object
var theFirstMark = viewerControl.getSelectedMarks()[0];

// move it forward
if (theFirstMark) viewerControl.moveMarkForward(theFirstMark);

moveMarkToBack(mark) → {IPCC.ViewerControl}

Moves the specified mark to the back. When the marks overlap, the marks that are higher in the internal `z-order` on a page are drawn over the ones that are lower.
Parameters:
Name Type Description
mark IPCC.Mark The mark being moved.
Throws:
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
// get the first selected Mark object
var theFirstMark = viewerControl.getSelectedMarks()[0];

// move it forward
if (theFirstMark) viewerControl.moveMarkForward(theFirstMark);

moveMarkToFront(mark) → {IPCC.ViewerControl}

Moves the specified mark to the front or to the top of internal `z-order` on a page. When the marks overlap, the marks with higher internal `z-order` are drawn over the ones that are lower.
Parameters:
Name Type Description
mark IPCC.Mark The mark being moved.
Throws:
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
// get the first selected Mark object
var theFirstMark = viewerControl.getSelectedMarks()[0];

// move it forward
if (theFirstMark) viewerControl.moveMarkForward(theFirstMark);

off(eventType) → {IPCC.ViewerControl}

Unsubscribe an event handler from a specified event type. Typically, an event is unsubscribed when you no longer want further notification of the event.
Parameters:
Name Type Description
eventType string A string specifying the event type. See IPCC.EventType for a list and description of all supported events.
`IPCC.Event~eventHandler` handler A function that was attached previously to the `ViewerControl`. **Note:** This must be the same function object previously passed to IPCC.ViewerControl#on. It cannot be an different object that is functionally equivalent.
See:
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
// Our event handler declaration
function handler(event) {
    alert("An event was fired: " + event.getType());
}

// Subscribe
viewerControl
    .on("PageChanged", handler)
    .on("PageCountReady", handler);

// Un-subscribe
viewerControl
    .off("PageChanged", handler)                        // Use string literals or the enum.
    .off(IPCC.EventType.PageCountReady, handler);  // Chain unsubscription.

on(eventType) → {IPCC.ViewerControl}

Subscribe an event handler to an event of a specified type.
Parameters:
Name Type Description
eventType string A string that specifies the event type. This value is case-insensitive. See IPCC.EventType for a list and description of all supported events.
`IPCC.Event~eventHandler` handler A function that will be called whenever the event is triggered.
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
// Create the viewer and get the ViewerControl object.
var viewerControl = $("#viewer").pccViewer(viewerOptions}).viewerControl;

// Our event handler declaration
function handler(event) {
    alert("An event was fired: " + event.getType());
}

viewerControl
    .on(IPCC.EventType.PageChanged, handler)    // Use the IPCC.EventType enum.
    .on(IPCC.EventType.PageDisplayed, handler)  // Chain event subscription.
    .on("PageLoadFailed", handler);                  // Use string literals instead of the EventType enum.

requestMarkupLayerNames(metadata)

Gets a list of all saved markups layer records from the server for the current document. This method utilizes an asynchronous server request to fetch the data, and returns a `Promise` to resolve the request. The [`onFulfilled`]`IPCC.Promise~onFulfilled` callback will receive an object representing the `annotationLayerRecords` persisted on the server. The [`onRejected`]`IPCC.Promise~onRejected` callback will receive an `IPCC.Error` object defining why the save function failed. The `IPCC.Promise~onFulfilled` function gets passed an `Array` of `Objects`. Each object will have 1) a `name` property, which is a string representation of the name used to save the markup layer record and 2) a `layerRecordId` property which is the string representation the uniquely identifies the record on the server.
Parameters:
Name Type Description
metadata Object An optional JSON object that will be passed to the web tier where it can be used for tasks like user identification. The JSON object will be transformed and then passed as GET parameter(s). The metadata JSON object must be flat and only contain values that are strings, numbers, or booleans.
Returns:
IPCC.Promise A `IPCC.Promise` object.
Example
viewerControl.requestMarkupLayerNames().then(
    function onSuccess(annotationLayerRecords) {
        var annotationLayerRecordsArray = [];
        for (var i = 0; i < annotationLayerRecords.length; i++) {
            annotationLayerRecordsArray.push(annotationLayerRecords[i].name);
        }
        alert(namesArray.join(', ');
    },
    function onFailure(error) {
        alert((error.message ? error.message : error));
    }
);

requestPageAttributes()

Requests attributes for the specified page. If the `pageNumber` parameter is invalid at the time the method is called, or the page does not exist in the document, then the returned `IPCC.Promise` object is rejected with the reason set to a `IPCC.Error` object with its code property set to RequestPageAttributesFailed. If a server error is encountered, then the returned `IPCC.Promise` object is rejected with the reason set to a `IPCC.Error` object with its code property set to Error. The `IPCC.Promise~onFulfilled` function will receive and `Object` with properties `width` and `height`, representing the reported width and height of each page.
Returns:
IPCC.Promise a `Promise` object.
Example
var promise = viewerControl.requestPageAttributes(10).then(
    function(pageAttributes) {
        alert('Page 10 attributes: width: ' + pageAttributes.width + ', height: ' + pageAttributes.height);
    },
    function(error) {
        alert('Page attributes retrieval for page 10 failed: ' + (error.message ? error.message : error));
    }
);

rotateDocument(degreesClockwise) → {IPCC.ViewerControl}

Rotates all pages in the document by the specified degrees clockwise, relative to each page's current orientation.
Parameters:
Name Type Description
degreesClockwise number Degrees clockwise to rotate each page. Valid values are multiples of 90: ..., `-270`, `-180`, `-90`, `0`, `90`, `180`, `270`, ...
Throws:
  • If value of `degreesClockwise` is not valid. The `Error` object will contain property `message` with details of the error.
    Type
    Error
  • If the IPCC.EventType.ViewerReady event was not fired prior to using this method.
    Type
    Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
viewerControl.rotateDocument(90);    // Rotates 90 degrees clockwise
viewerControl.rotateDocument(-90);   // Rotates 90 degrees counter-clockwise
viewerControl.rotateDocument(180);   // Rotates 180 degrees
viewerControl.rotateDocument(540);   // Also, rotates 180 degrees
viewerControl.rotateDocument(100);   // Throws!

rotatePage(degreesClockwise) → {IPCC.ViewerControl}

Rotates the current page by the specified degrees clockwise, relative to the page's current orientation.
Parameters:
Name Type Description
degreesClockwise number Degrees clockwise to rotate the page. Valid values are multiples of 90: ..., `-270`, `-180`, `-90`, `0`, `90`, `180`, `270`, ...
Throws:
  • If value of `degreesClockwise` is not valid. The `Error` object will contain property `message` with details of the error.
    Type
    Error
  • If the IPCC.EventType.ViewerReady event was not fired prior to using this method.
    Type
    Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
viewerControl.rotatePage(90);    // Rotates 90 degrees clockwise
viewerControl.rotatePage(-90);   // Rotates 90 degrees counter-clockwise
viewerControl.rotatePage(180);   // Rotates 180 degrees
viewerControl.rotatePage(540);   // Also, rotates 180 degrees
viewerControl.rotatePage(100);   // Throws!

saveMarkup(recordName, optionsopt)

Saves all markups in the document to the server as a record with a specified name. If the parameter `recordName` is not a string, then the `IPCC.Promise` object that is returned will be rejected with the reason set to a `IPCC.Error` object with its code property set to InvalidArgument. If the parameter `recordName` contains invalid characters in the name, then the `IPCC.Promise` object that is returned will be rejected with the reason set to a `IPCC.Error` object with its code property set to InvalidCharactersFilename. If a server error is encountered, then the returned `IPCC.Promise` object is rejected with the reason set to a `IPCC.Error` object with its code property set to Error. If AJAX is not supported, then the returned `IPCC.Promise` object is rejected with the reason set to a `IPCC.Error` object with its code property set to AjaxUnsupported. The `IPCC.Promise~onFulfilled` function will receive the `recordName` string as its only argument. **Note:** This method will overwrite any previous markup stored with the same name. To prevent duplicates, check to see if the name already exists by using IPCC.ViewerControl#getSavedMarkupNames.
Parameters:
Name Type Attributes Description
recordName string Name of the annotation record. The markup is saved to an XML file using a filename that includes a unique ID for the document being viewed and the provided annotation record name, so valid filename characters are required. When later viewing the document, the saved markup can be loaded by passing the record name to the IPCC.ViewerControl#loadMarkup method.
options IPCC.ViewerControl~SaveMarkupOptions <optional>
This optional parameter specifies options for the markup types to be saved. The IPCC.ViewerControl~SaveMarkupOptions details the options object.
Returns:
IPCC.Promise a `Promise` object, on success returns the given record name after the record is saved.
Example
// The following example will save all annotation mark types. 
viewerControl.saveMarkup('cool name').then(
    function success(name) {
        alert('Markup was saved as "' + name + '"');
    },
    function fail(error) {
        alert('Markup was not saved. ' + (error.message ? error.message : error));
    }
);

saveMarkupLayer(id)

Save a markup layer record to the server. This method saves a single layer to the server asynchronously, and returns a `Promise` to resolve the request. The [`onFulfilled`]`IPCC.Promise~onFulfilled` callback will receive an object containing the `layerRecordId` of the saved layer. The [`onRejected`]`IPCC.Promise~onRejected` callback will receive an `IPCC.Error` object defining why the save function failed.
Parameters:
Name Type Description
id String The ID of the layer, as returned by `layer.getId()`.
Returns:
IPCC.Promise A `Promise` object.
Example
// save the current active layer
var layer = viewerControl.getActiveMarkupLayer();

viewerControl.saveMarkupLayer(layer.getId()).then(
    function onSuccess(layerInfo){
        console.log('layer saved successfully', layerInfo.layerRecordId);
    },
    function onFailure(reason){
        console.log('layer failed to save:', reason.code, reason.message);
    }
);

scrollBy(offsetX, offsetY) → {IPCC.ViewerControl}

Scrolls by specified offset.
Parameters:
Name Type Description
offsetX number integer that contains value to scroll horizontally. Negative value will scroll to the left.
offsetY number integer that contains value to scroll vertically. Negative value will scroll to the top.
Throws:
  • If IPCC.EventType.ViewerReady event was not fired prior to using this method.
    Type
    Error
  • If target is not an Object with valid offsetX and offsetY values.
    Type
    Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
// scroll by specified offset
viewerControl.scrollBy(100, 100);

selectMarks(marks) → {IPCC.ViewerControl}

Selects the marks provided in the `Array` parameter. **Note:** This method ignores any Mark objects with the interaction mode set to IPCC.Mark.InteractionMode.SelectionDisabled.
Parameters:
Name Type Description
marks Array.<IPCC.Mark> An array of IPCC.Mark objects that exist in the document and need to be selected.
Throws:
  • If IPCC.EventType.ViewerReady event was not fired prior to calling this method.
    Type
    Error
  • If any of the mark objects are not valid objects, the id of the mark provided does not match the id of mark loaded in the viewer, or the mark provided was not previously added to the document pages.
    Type
    Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
// get all of the marks
var allMarks = viewerControl.getAllMarks();

// select all of them
viewerControl.selectMarks(allMarks);

setActiveMarkupLayer(A)

Sets the viewer control's active markup layer.
Parameters:
Name Type Description
A IPCC.MarkupLayer markup layer.
Throws:
Example
viewerControl.loadMarkupLayers('abc123').then(
    function onSuccess(layers){
        var activeMarkupLayer = viewerControl.setActiveMarkupLayer(layers[0]);
    },
    function onFailure(reason){
        console.log('layer failed to load:', reason.code, reason.message);
    }
);

setCurrentMouseTool(name) → {IPCC.ViewerControl}

Sets the current mouse tool of the viewer by name. See the help section titled "Custom Mouse Tools" for a list of the existing default mouse tools in the viewer.
Parameters:
Name Type Description
name string The name used when creating the mouse tool. This value is case-insensitive.
See:
Throws:
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl

setGamma(gammaFactor) → {IPCC.ViewerControl}

Sets the gamma factor for the document. Values from 1 to 10 will darken the document. Values from 0 to 1 will effectively lighten it. Note: This setting only affects viewing and is not persisted when printing or burning.
Parameters:
Name Type Description
gammaFactor number The gamma factor to set the Gamma for the document to.
Throws:
If the gamma factor is not a valid number between 0 and 10 inclusive.
Type
Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
viewerControl.setGamma(5); // Darkens content by a factor of 5
viewerControl.setGamma(0.5) // Lightens content by a factor of 0.5

setPageLayout(pageLayout) → {IPCC.ViewerControl}

Sets the layout of the pages. This property defines the placement or arrangement of the pages in the viewer. The default page layout is `"Vertical"`, in which the pages are displayed as a single vertical column and a vertical scroll bar is displayed to bring into view the pages that are not in view. The `"Horizontal"` option displays the pages as a single horizontal row and has a horizontal scroll bar to bring into view the pages that are not in the view. Comments are only supported when using vertical page layout. If the comments panel is open, setting the page layout to horizontal will close the comments panel.
Parameters:
Name Type Description
pageLayout IPCC.PageLayout Display pages using this layout.
See:
Throws:
If the `pageLayout` value is unknown.
Type
Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
viewerControl.setPageLayout(IPCC.PageLayout.Horizontal);

setPageNumber(pageNumber) → {IPCC.ViewerControl}

Sets the current page of the viewer to the specified page number.
Parameters:
Name Type Description
pageNumber number | string The 1-based page number of the page. A string representation of a valid number is also accepted as a parameter.
Throws:
  • If the parameter `pageNumber` is less than 1 or greater than the value returned by IPCC.ViewerControl#getPageCount.
    Type
    Error
  • If the parameter `pageNumber` is not a number or a string representation of a number.
    Type
    Error
  • If the parameter `pageNumber` is not an integer page number.
    Type
    Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
// first create the pccViewer : Note: if the viewer object has already been created, do not re-create it.
var viewerControl = $("#viewer").pccViewer(viewerOptions).viewerControl;

var pageNumberSet = 2;
function pageChangedHandler(event) {
    var pageNumber = viewer.getPageNumber();
    if(pageNumber === pageNumberSet) {
        //now unsubscribe the event Note: do not unsubscribe if future notifications are required.
        viewerControl.off("PageChanged", pageChangedHandler);
        alert("Viewer was navigated to the desired page successfully");
    }
}
// Subscribe to PageChanged event exposed by the API
viewerControl.on("PageChanged", pageChangedHandler);
viewerControl.setPageNumber(pageNumberSet);

setScaleFactor(scaleFactor) → {IPCC.ViewerControl}

Sets the scale factor of the viewer. **Note:** The viewer has minimum and maximum scale limits. The limits depend on the size of the pages. check IPCC.ViewerControl#getMinScaleFactor and IPCC.ViewerControl#getMaxScaleFactor to determine the minimum and maximum scale.
Parameters:
Name Type Description
scaleFactor number A value indicating the scale factor to use in the viewer, with 1 being 100% zoom.
Throws:
  • If the `scaleFactor` value is out of range.
    Type
    Error
  • If the IPCC.EventType.ViewerReady event was not fired prior to calling this method.
    Type
    Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
viewerControl.setScaleFactor(.5); // Zoom the document to 50% of its actual size.

setSharpening(sharpeningFactor) → {IPCC.ViewerControl}

Sets the sharpening factor for the document. Note: This setting only affects viewing and is not persisted when printing or burning.
Parameters:
Name Type Description
sharpeningFactor number The sharpening factor to set the Sharpening for the document to.
Throws:
If the sharpening factor is not a valid integer between 0 and 100 inclusive.
Type
Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
viewerControl.setSharpening(60);

setSvgLineWidthMultiplier(lineWidthMultiplier) → {IPCC.ViewerControl}

Numeric value which all SVG line width values should be multipled by. Must be greater than 0 and must not be greater than 100. To make lines twice as thick as they originally were, use a value of 2. To make lines half as thick as they originally were, use a value of 0.5, etc. To reset lines to their original thickness, use a value of 1. Note: This setting only affects viewing and is not persisted when printing or burning.
Parameters:
Name Type Description
lineWidthMultiplier number The line width multiplier for svg lines to set for the document.
Throws:
If amount is not greater than zero or is greater than 100
Type
Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
viewerControl.setSvgLineWidthMultiplier(50); 

setViewMode(viewMode) → {IPCC.ViewerControl}

Sets the view mode. When set to `"Document"` or `"EqualFitPages"`, this property only has an effect on documents with different sized pages. Setting the view mode to `"Document"` maintains the relative size of each page when displaying a document. For example, if page 2 is smaller than page 1, it will appear smaller. Setting the view mode to `"EqualFitPages"` scales each page so that their width is the same. For example, if page 2 is smaller than page 1, it will be scaled larger so that its width is equal to the width of page 1. Setting the view mode to `"SinglePage"` structures the viewer so that only a single page is shown at a time. Each page is scaled to fit within a view box, which is the initial size of the viewer and increases in size when zooming in (and decreases in size when zooming out). After the viewer initializes, the view mode may not be changed to or from SinglePage view mode (or an exception will occur).
Parameters:
Name Type Description
viewMode IPCC.ViewMode Display pages using this mode.
See:
Throws:
  • If the `viewMode` value is unknown.
    Type
    Error
  • If the IPCC.EventType.ViewerReady event was not fired prior to using this method.
    Type
    Error
  • If setting the value to "SinglePage". This value must be set during initialization time. See IPCC.ViewerControl~ViewerControlOptions for mode details on the `viewMode` initialization parameter.
    Type
    Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
viewerControl.setViewMode(IPCC.ViewMode.EqualFitPages);   // Scale each page so that their width is the same.

showMarks(marks) → {IPCC.ViewerControl}

Shows the specified marks.
Parameters:
Name Type Description
marks Array.<IPCC.Mark> An Array of objects of type IPCC.Mark.
Throws:
  • If IPCC.EventType.ViewerReady event was not fired prior to using this method.
    Type
    Error
  • If any of the marks passed in are not valid objects of the type IPCC.Mark.
    Type
    Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
// shows all selected marks
viewerControl.showMarks(viewer.getSelectedMarks());

zoomIn(zoomFactor) → {IPCC.ViewerControl}

Zoom in on the document by the specified `zoomFactor`. **Note:** The viewer has minimum and maximum scale limits. `zoomIn` will only change the viewer's scale up to, but not past, the maximum scale limit. `zoomIn` does not give an indication if the actual scale change was less than the requested zoom factor because the limit was reached. Instead, check IPCC.ViewerControl#atMaxScale to determine if the viewer is at max scale.
Parameters:
Name Type Description
zoomFactor number Zoom in by this factor. Valid values are between `1.01` and `20`
See:
Throws:
  • If the `zoomFactor` value is invalid.
    Type
    Error
  • If the IPCC.EventType.ViewerReady event was not fired prior to calling this method.
    Type
    Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
viewerControl.zoomIn(1.5);   // Zoom in by 1.5x, or to the maximum scale.
viewerControl.zoomIn(5);     // Zoom in by 5x, or to the maximum scale.

viewerControl.zoomIn(100);   // Throws!
viewerControl.zoomIn(1);     // Throws!

zoomOut(zoomFactor) → {IPCC.ViewerControl}

Zoom out on the document by the specified `zoomFactor`. **Note:** The viewer has minimum and maximum scale limits. `zoomOut` will only change the viewer's scale down to, but not past, the minimum scale limit. `zoomOut` does not give an indication if the actual scale change was less than the requested zoom factor because the limit was reached. Instead, check IPCC.ViewerControl#atMinScale to determine if the viewer is at minimum scale.
Parameters:
Name Type Description
zoomFactor number Zoom out by this factor. Valid values are between `1.01` and `20`.
See:
Throws:
  • If the `zoomFactor` value is invalid.
    Type
    Error
  • If the IPCC.EventType.ViewerReady event has not fired prior to calling this method.
    Type
    Error
Returns:
The `ViewerControl` object on which this method was called.
Type
IPCC.ViewerControl
Example
viewerControl.zoomOut(1.5);   // Zoom out by 1.5x, or to the minimum scale.
viewerControl.zoomOut(5);     // Zoom out by 5x, or to the minimum scale.

viewerControl.zoomOut(100);   // Throws!
viewerControl.zoomOut(1);     // Throws!

Type Definitions

SaveMarkupOptions

The IPCC.saveMarkup API method takes a second optional parameter. This parameter is in the form of an object and provides options for saving marks to the server.
Type:
  • Object
Properties:
Name Type Attributes Default Description
includeAnnotations boolean <optional>
true Indicates whether annotation mark types should be saved.

ViewerControlOptions

These options are available and processed directly by the ViewerControl. When using the jQuery Plugin, external:jQuery.fn#pccViewer, these options can be passed in along with external:jQuery.fn~Options, and they will be passed into ViewerControl.
Type:
  • Object
Properties:
Name Type Attributes Default Description
documentID string REQUIRED The ID of the document to load.
imageHandlerUrl string REQUIRED The end point of the web tier services that support the viewer.
language Object <optional>
Specifies the language to use for the text in the ViewerControl. The options here are a subset of the external:jQuery.fn~LanguageOptions object. These values are used directly by the ViewerControl, and are passed in by the jQuery Plugin, external:jQuery.fn#pccViewer. When creating a custom UI using ViewerControl directly, these options will need to be passed in during initialization. If they `language` element is not present with the following properties, ViewerControl will use the English language defaults.
Properties
Name Type Attributes Default Description
pageLoadFailed string <optional>
"Page Load Failed" Text to use for "Page Load Failed"
pageLoadFailedRetry string <optional>
"Retry" Text to use for "Retry"
viewMode string <optional>
"Document" The mode used to view documents containing different sized pages. See the IPCC.ViewMode enumeration for details on each view mode.
pageLayout string <optional>
"Vertical" The layout used to arrange pages in the viewer. See the IPCC.PageLayout enumeration for details on each page layout.
pageRotation number <optional>
0 The amount in degrees clockwise to rotate each page. Valid values are multiples of 90: ..., `-270`, `-180`, `-90`, `0`, `90`, `180`, `270`, ...