PrizmDoc® v14.1 Release - Updated
PrizmDoc / Developer Guide / PrizmDoc / How to Customize PrizmDoc / Scroll the Viewer Programmatically
In This Topic
    Scroll the Viewer Programmatically
    In This Topic

    The ViewerControl API offers two methods for scrolling the Viewer:

    • The 'scrollToAsync(target)' method will scroll the Viewer to a specified target/location within the Viewer.
    • The 'scrollBy(offsetX, offsetY)' method will scroll the Viewer by a specified number of pixels.

    Scroll to a Specific Target

    The API enables scrolling to a specific target or location within the Viewer. Possible targets are:

    • a mark (annotation, redaction, or signature)
    • a conversation
    • a search result, or
    • a point on a specific page

    Use the method PCCViewer.ViewerControl#scrollToAsync(target) to scroll to a specific target, as shown in the following code example:

    Example

    myViewerControl
        .scrollToAsync({
            pageNumber: 2,
            x: 500,
            y: 500
        })
        .then(
            function onFulfilled() {
                alert("The point was scrolled into view.")
            },
            function onRejected() {
                alert("Something went wrong: ")
            }
        );
    
    

    The scrollToAsync method returns a PCCViewer.Promise that is fulfilled when the target is scrolled into view and has been displayed. In the onFulfilled callback is an appropriate time to take additional programmatic actions against the target (e.g. put a mark in text editing mode).

    The method will attempt to center the target. If the full target does not fit at the current scale, then it will attempt to center the top left corner of the target. The method will not scroll past the bounds of the document, so in some cases it will scroll to as close to centering the target as possible.

    There is also the ViewerControl#scrollTo(target) method that returns the ViewerControl object rather than a promise. It is recommended that you use scrollToAsync, unless method chaining is desired.

    Scroll by a Number of Pixels

    The API enables scrolling the content in the Viewer by a specified number of pixels. The method PCCViewer.ViewerControl#scrollBy(offsetX, offsetY) allows scrolling up, down, left, or right. Scrolling down or right is performed by passing positive offset values. Scrolling up or left is performed by passing negative offset values.

    The following example demonstrates how to scroll down using this method:

    Example

    // Scroll down by 100 pixels
    myViewerControl.scrollBy(0, 100);
    
    

    This method will scroll content until it reaches the bounds of the document, at which point the method will stop scrolling in that direction.

    When the ViewerControl is in SinglePage view mode, this method will only scroll within the current page, it will not change pages.