The HTML5 Viewer provides a simple UI that offers viewing functionality.
ViewerControl exists with the ImageGear.Web distribution under the IPCC namespace and can be instantiated independently as a stand-alone document viewer with no user interface.
From an instantiated IGViewer.Viewer, its underlying IPCC.ViewerControl instance can be accessed as demonstrated by the following code example:
JS |
Copy Code |
---|---|
<script type="text/javascript"> var igViewer, ipccViewerControl; $(function () { igViewer = new IGViewer.Viewer("#viewer", { documentID: "mydocument.pdf", imageHandlerUrl: "/ImageGearService.svc", viewerIconsPath: "/Assets/Viewer/icons" }); ipccViewerControl = igViewer.viewerControl; }); </script> |
Once you obtain a reference to the ViewerControl instance beneath the Viewer GUI, you can use it to obtain information regarding the current view state, manipulate it directly, and register custom event listeners. A description of available ViewerControl properties, methods, and event types follows.
ECMAScript 2015 accessor properties function in a manner similar to C# properties in that they allow code execution upon getting or setting a value to be associated with the property’s identifier. Any reference to the accessor property will execute code that returns its value. Assigning a value to an accessor property using "object.accessorProperty = value;" will execute code which handles setting of the property to the desired value.
For ease of use on a supported browser, certain aspects of ViewerControl are configurable through accessor properties, however, there are always a set of getter/setter methods for each property to accommodate browsers which to not support accessor properties.
Accessor |
Getter |
Setter |
Type |
Description |
atMaxScale |
getAtMaxScale() |
N/A |
boolean |
(accessor read-only) Gets a value that indicates whether the viewer is currently at the maximum scale factor. If this value is true, ViewerControl will be unable to zoom in 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 ViewerControl is resized. Throws Error:
|
atMinScale |
getAtMinScale() |
N/A |
boolean |
(accessor read-only) Gets a value that indicates whether the viewer is currently at the minimum scale factor. If this value is true, ViewerControl will be unable to zoom out 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 ViewerControl is resized. Throws Error:
|
pageCount |
getPageCount() |
N/A |
number |
(accessor read-only) 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 event to be notified when the viewer gets the page count from the server. Will report a page count of 1 before the PageCountReady event fires. |
pageNumber |
getPageNumber() |
setPageNumber(x) |
number |
Gets or sets the currently displayed page starting at index 1 (the page number of the first page is 1). Throws Error:
|
scaleFactor |
getScaleFactor() |
setScaleFactor(x) |
number |
Gets or sets 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. The viewer has minimum and maximum scale limits. The limits depend on the size of the pages. Check IPCC.ViewerControl.minScaleFactor and IPCC.ViewerControl.maxScaleFactor to determine minimum and maximum scale.
Throws Error:
|
viewMode |
getViewMode() |
setViewMode(x) |
string |
Gets or sets the view mode. This defines how the document pages will be scaled. Must be one of the values in the IPCC.ViewMode enum described in a later subsection "ViewerControl Enum Parameters". 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 view 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). Throws Error:
|
N/A |
getGamma() |
setGamma(x) |
number |
Gets or 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. Throws Error:
|
N/A |
getPageLayout() |
setPageLayout(x) |
string |
Gets or 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 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 view. Throws Error:
|
N/A |
getSharpening() |
setSharpening(x) |
number |
Gets or sets the sharpening factor for the document. The sharpening factor is a valid integer between 0 and 100 inclusive. Throws Error:
|
N/A |
getSvgLineWidthMultiplier() |
setSvgLineWidthMultiplier(x) |
number |
Gets or sets the current multiplier used to adjust SVG line widths in the document. This is a numeric value which all SVG Line width values should be multiplied by. This value 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. To reset lines to their original thickness, use a value of 1. Throws Error:
|
Method |
Description | ||
changeToFirstPage() |
Sets the current page of the viewer to the first page of the document. | ||
changeToLastPage() |
Sets the current page of the viewer to the last known page of the document. | ||
changeToNextPage() |
Sets the current page of the viewer to the next page of the document. | ||
changeToPrevPage() |
Sets the current page of the viewer to the previous page of the document. | ||
destroy() |
Closes the ViewerControl and cleans up its resources. After this action, a new viewer can be created in its place. This method should not be called manually. Instead, use the destroy method of the overlying viewer or simply construct a new IGViewer using the same DOM Element. | ||
fitContent(fitType) |
Changes the scaling (zoom) of the document to fit the content in the viewer. fitType must be a value in the IPCC.FitType enum, described in the later subsection "ViewerControl Enum Paramters". Throws Error:
| ||
getPageRotation(pageNumber) |
Gets the page rotation value for the specified page number. Throws Error:
| ||
pageNumber |
number |
Optional. A 1-based page number of the page whose rotation to retrieve. If this parameter is not provided, the implied pageNumber will be that of the currently displayed page. | |
rotatePage(degsClockwise) |
Rotates the current page by the specified degrees clockwise, relative the page’s current orientation. Throws Error:
| ||
degsClockwise |
number |
Degrees clockwise to rotate each page. Values values are multiples of 90: {..., -270, -180, -90, 0, 90, 180, 270, …} | |
rotateDocument(degsClockwise) |
Rotates all pages in the document by the specified degrees clockwise, relative to each page’s current orientation. Throws Error:
| ||
degsClockwise |
number |
Degrees clockwise to rotate each page. Values values are multiples of 90: {..., -270, -180, -90, 0, 90, 180, 270, …} | |
scrollBy(offsetX, offsetY) |
Scrolls by the specified offset. Throws Error:
| ||
offsetX |
number |
Integer that specifies the value to scroll horizontally. Negative values will scroll to the left. | |
offsetY |
number |
Integer that specifies the value to scroll vertically. Negative values will scroll upward. | |
zoomIn(zoomFactor) |
Zoom in on the document by the specified zoomFactor. 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.
Throws Error:
| ||
zoomFactor |
number |
Zoom in by this factor. Valid values are between 1.01 and 20. | |
zoomOut(zoomFactor) |
Zoom out on the document by the specified zoomFactor. The viewer has minimum and maximum scale limits. zoomOut willl 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.
Throws Error:
| ||
zoomFactor |
number |
Zoom out by this factor. Valid values are between 1.01 and 20. |
The FitType enumeration defines fit types known by IPCC.ViewerControl. The ViewerControl uses a specified fit type to set or update the scaling of the pages displayed in the viewer.
Enum Property |
Type |
Value |
Description |
IPCC.FitType.FullWidth |
string |
"FullWidth" |
The viewer scales the content to fill the width of the viewer. |
IPCC.FitType.ShrinkToWidth |
string |
"ShrinkToWidth" |
The viewer will scale down the content until it fits fully width-wise into view. The page will into be scaled up if it already fits. |
IPCC.FitType.ActualSize |
string |
"ActualSize" |
The viewer shows the content at its actual size. The content is not scaled. |
IPCC.FitType.FullHeight |
string |
"FullHeight" |
The viewer scales the content to fill the height of the viewer based on the largest known page height. |
IPCC.FitType.FullPage |
string |
"FullPage" |
The viewer scales the content ot best fit the largest known page in the viewer. |
The PageLayout enumeration defines page layouts known by IPCC.ViewerControl. The ViewerControl uses a page layout to set or update the placement or arrangement of the pages in the viewer.
Enum Property |
Type |
Value |
Description |
IPCC.PageLayout.Horizontal |
string |
"Horizontal" |
Pages are displayed as a single horizontal row and a horizontal scroll bar is displayed to bring into view the pages that are not in view. |
IPCC.PageLayout.Vertical |
string |
"Vertical" |
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 ViewMode enumeration defines view modes known by IPCC.ViewerControl. The ViewerControl uses a view mode to set or update how documents that contain different sized pages are displayed in the viewer.
Enum Property |
Type |
Value |
Description |
IPCC.ViewMode.Document |
string |
"Document" |
The viewer 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. |
IPCC.ViewMode.SinglePage |
string |
"SinglePage" |
The viewer displays a single page 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 (an Error will be thrown in this case). |
IPCC.ViewMode.EqualFitPages |
string |
"EqualFitPages" |
The viewer scales each page so that their width is the same, when using vertical page layout. 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. If using horizontal page layout, the viewer scales each page so that their height is the same. |
ViewerControl does its own internal routing of custom events and provides the following methods to register and unregister event handlers. An event handler is a function which accepts a single "event" parameter which contains information about the event that has occurred. For certain event types, ViewerControl may augment the event object passed to the handler with properties which relay further information about the event.
Method |
Description | ||
ViewerControl.on(eventType, handler) |
Subscribe an event handler to an event of a specified type. | ||
eventType |
string |
A string that specifies the event type. This value is case-insensitive. Refer to the list of event types below. | |
handler |
function |
A function that will be called whenever the event is triggered | |
ViewerControl.off(eventType, handler) |
Unsubscribe an event handler from a specified event type. Typically, an event is unsubscribed from when you no longer want further notification of the event. | ||
eventType |
string |
A string that specifies the event type. This value is case-insensitive. Refer to the list of event types below. | |
handler |
function |
A function that was previously registered with the same ViewerControl instance for that same eventType. This must be the same function object previously passed to IPCC.ViewerControl.on(...). It cannot be a different object that is functionally equivalent. |
Enum Property |
Value |
Description |
IPCC.EventType.ViewerReady |
"ViewerReady" |
Triggered when the Viewer is ready. Augmented properties of the event object for this event: None. |
IPCC.EventType.PageCountReady |
"PageCountReady" |
Triggered when the viewer has an actual page count from the server and the consumer can begin to interact with the viewer interfaces. Augmented properties of the event object for this event:
|
IPCC.EventType.PageChanged |
"PageChanged" |
Triggered when the viewer changed the current page. Augmented properties of the event object for this event: None |
IPCC.EventType.PageLoadFailed |
"PageLoadFailed" |
Triggered when the viewer fails to load a page. Augmented properties of the event object for this event:
|
IPCC.EventType.PageDisplayed |
"PageDisplayed" |
Triggered when the viewer has displayed a page. If the content of a page is large, for example, an engineering drawing with several hundred nodes, then the browser may be busy still rendering/preparing the content when this event gets fired. Augmented properties of the event object for this event:
|
IPCC.EventType.PageRotated |
"PageRotated" |
Triggered when the viewer has rotated a page. Augmented properties of the event object for this event:
|
IPCC.EventType.DocumentRotated |
"DocumentRotated" |
Triggered when the rotation of all pages in the document changes. Augmented properties of the event object for this event:
|
IPCC.EventType.ScaleChanged |
"ScaleChanged" |
Triggered when the scaling of page(s) in the viewer changed. This may occur as a result of a number of user actions including zooming, fit type change, viewer mode change, or scale change. Augmented properties of the event object for this event:
|
IPCC.EventType.Click |
"Click" |
Triggered when a user clicks a page. Augmented properties of the event object for this event:
|
IPCC.EventType.PageOpening |
"PageOpening" |
Triggered when the width and height page attributes are retrieved. Note that this event will fire whenever a page opens, so if a page opens, it will fire, and if the page is scrolled out of view, disposed, and then scrolled back into view, the event will fire again. Augmented properties of the event object for this event:
|
JS |
Copy Code |
---|---|
<script type="text/javascript"> var igViewer, ipccViewerControl; $(function () { igViewer = new IGViewer.Viewer("#viewer", { documentID: "mydocument.pdf", imageHandlerUrl: "/ImageGearService.svc", viewerIconsPath: "/Assets/Viewer/icons" }); ipccViewerControl = igViewer.viewerControl; ipccViewerControl.on( IPCC.EventType.PageChanged, function (evt) { console.log("page changed... " + "current page number is: " + evt.pageNumber); } ); }); </script> |