Skip to main content
Version: v2026.0.0

JavaScript API

The ARender viewer exposes a JavaScript API that lets host pages interact with the viewer without page reloads. It is available on the window object as arender once the viewer has initialized.

Initialization

The viewer calls window.ARenderJSAPI() once the GWT application has finished loading. Register this global function before embedding the viewer to execute code as soon as the API is ready:

function ARenderJSAPI() {
// arender.jsapi is now available
console.log('Current document:', arender.jsapi.getCurrentDocumentId());
}

To run a startup script from the server side, set the arenderjs.startupScript property to the URL of a JavaScript file. ARender calls window.ARenderJSAPICallStartupScript(url) to load it.

Top-level namespace: arender.jsapi

The root object of the API. All sub-APIs are accessible from here.

Document loading and navigation

MethodParametersReturnsDescription
loadDocument(url, onLoad, onError)url: string, onLoad: function(docId), onError: function(docId, message)voidLoads a document by URL and returns its ID in the callback
loadDocuments(gsonDocument, onError, onLoad)gsonDocument: string, onError: function, onLoad: function(docId)voidLoads a document described as a JSON structure
openDocument(documentId)documentId: stringvoidOpens a previously loaded document by ID
openDocument(documentId, resetUI)documentId: string, resetUI: booleanvoidOpens a document, optionally resetting the UI state
openDocument(documentId, page)documentId: string, page: numbervoidOpens a document at a specific page (0-based)
cancellableLoadDocument(url, onLoad, onError)url: string, onLoad: function, onError: functionvoidLike loadDocument but prompts the user if unsaved annotations exist
closeDocument()voidCloses the current document
closeErrorPopup()voidDismisses any error popups
getCurrentDocumentId()stringReturns the ID of the page-level document currently shown in the content area
getMasterDocumentId()stringReturns the root container document ID
askChangeDocument(type, documentId)type: 'Previous'|'Next'|'First'|'Last'|'ByDocumentId', documentId?: stringvoidNavigates to another document in the current tree
askChangePage(type, offset, position)type: 'Relative'|'Index'|'Absolute'|'NoChange', offset: number, position: PageRelativePositionvoidNavigates to a page
newPageRelativePosition(x, y, w, h)x, y, w, h: floatPageRelativePositionBuilds a position rectangle for use with askChangePage
getPageForNamedDestination(documentId, destination, handler)documentId: string, destination: string, handler: function(pageNumber)voidResolves a named destination to a page number

Example: load and open a document

arender.jsapi.loadDocument('/path/to/doc.pdf',
function(docId) { arender.jsapi.openDocument(docId); },
function(docId, msg) { console.error('Load failed:', msg); }
);
MethodParametersDescription
enablePDFDocumentHyperlinks(enable)enable: booleanShows or hides PDF hyperlinks for the current document
disallowClickOnHyperlinks(disallow)disallow: booleanPrevents hyperlink clicks without hiding the overlays
enableInternalPDFDocumentHyperlinks(documentId)documentId: DocumentIdEnables internal (same-document) hyperlinks
disableInternalPDFDocumentHyperlinks(documentId)documentId: DocumentIdDisables internal hyperlinks
enableExternalPDFDocumentHyperlinks(documentId)documentId: DocumentIdEnables external (URL) hyperlinks
disableExternalPDFDocumentHyperlinks(documentId)documentId: DocumentIdDisables external hyperlinks
notifyHyperlinkTarget(target)target: stringProvides a URL target for a hyperlink awaiting a destination

Text selection (lasso mode)

MethodParametersDescription
askActivateLassoMode(lassoId)lassoId: stringEnables rectangular text-selection mode; the ID is returned in the callback
askDeactivateLassoMode()Deactivates lasso mode

Annotations (save / display)

MethodParametersDescription
displayComment(documentId, display)documentId: string, display: 'All'|'Unresolved'|'Resolved'Filters annotation comments shown in the explorer
askDownloadDocument(documentId, title, suffix)documentId: string, title?: string, suffix?: stringTriggers a direct download of a document by ID
changeConfigurableElement(name, enabled)name: string, enabled: booleanToggles a named UI element at runtime

Plugins

MethodParametersDescription
preparePluginEvent(key, value, pluginName)key, value, pluginName: stringQueues a parameter for the next plugin open event
clearPluginEvent(pluginName)pluginName: stringClears queued plugin parameters
openPlugin(pluginName, openInMultiView)pluginName: string, openInMultiView: booleanOpens a plugin by name
getHtmlPluginName()Returns the constant 'html-plugin'

Sub-API accessors

MethodReturns
getDocumentBuilder()arender.documentBuilder
getDocumentLayout()arender.documentLayout
getDocumentMetadata()arender.documentMetadata
getZoomJSAPI()arender.zoomJSAPI
getRotateJSAPI()arender.rotateJSAPI
getPrintJSAPI()arender.showPrintDialogJSAPI
getFullScreenJSAPI()arender.fullScreenJSAPI
getSearchJSAPI()arender.searchJSAPI
getGenericNotificationJSAPI()arender.genericNotificationJSAPI
getDownloadDocumentJSAPI()arender.downloadDocumentJSAPI
getZoomGlassJSAPI()arender.zoomGlassJSAPI
getThumbnailsJSAPI()arender.thumbnailsJSAPI
getDocumentCompareJSAPI()arender.documentCompare
getScreenSplitJSAPI()arender.screenSplitJSAPI
getAnnotationJSAPI()arender.annotationJSAPI (loaded asynchronously)
onAnnotationModuleReady(callback)Calls callback(annotationJSAPI) once the annotation module is loaded

Event callbacks

Register callbacks to react to viewer events. All register* methods can be called before or after document load.

MethodCallback signatureDescription
registerNotifyPageChangeEvent(cb)cb(currentPage, pageCount, documentId)Fires when the displayed page changes
registerCurrentDocumentChangeEvent(cb)cb(documentId, title, metadata)Fires when the active document changes
registerNotifyLoadingErrorEvent(cb)cb(documentId, message)Fires when a document fails to load
registerNotifyLogEvent(cb)cb(event, level, message, stackTrace)Intercepts all toaster log events
registerGenericEventListener(cb)cb(eventClassName)Fires for every event on the internal bus
registerAllAsyncModulesStartedEvent(cb)cb()Fires when all async modules have finished initializing
registerPanelLoadedConfigurationEvent(cb)cb()Fires when the top-panel configuration is loaded
registerTopPanelRefreshedEvent(cb)cb()Fires when the top-panel buttons are refreshed
registerHyperlinkDisplayHookEvent(docId, cb)cb(documentId, internal, external)Fires when PDF hyperlinks are displayed
registerCommentDisplayHookEvent(docId, cb)cb(documentId, displayState)Fires when the comment display state changes
registerAnnotationsSavedEvent(cb)cb(success, created, updated, deleted)Fires after annotations are saved
registerNotifyLassoSelectedTextEvent(cb)cb(text, lassoId)Fires when the user completes a lasso text selection
registerNotifyHyperlinkToggleTargetModeEvent(cb)cb(activated)Fires when hyperlink target-selection mode is toggled
registerDisplayLinkHandler(cb)cb(documentId, linkId, isAnnotation, event)Fires when a link is about to be rendered; use setLinkStyle, setLinkColor, setLinkOpacity to override appearance
registerExternalBookmarkHandler(cb)cb(documentId, fileName, namedDestination, id)Fires when the user clicks an external bookmark

Example: react to page changes

arender.jsapi.registerNotifyPageChangeEvent(function(page, count, docId) {
console.log('Page ' + (page + 1) + ' of ' + count);
});

Example: intercept annotations saved

arender.jsapi.registerAnnotationsSavedEvent(function(success, created, updated, deleted) {
if (success) {
console.log('Saved: +' + created + ' ~' + updated + ' -' + deleted);
}
});

Namespace: arender.documentBuilder

Controls the document builder panel. For a complete description of the document builder feature, data model, and save behaviors, see Document builder.

MethodDescription
open()Opens the document builder panel
close()Closes the document builder panel
toggle()Toggles the document builder panel
reset()Resets the current assembly
saveFirstDocument(download, delete, freeze, behavior)Saves the first output document
saveAllDocuments(handler, download, delete, freeze, behavior)Saves all output documents
createEmptyDocument()Adds an empty output document slot
createCustomDocument(jsonContent, options)Creates an output document from JSON

Callbacks: registerNotifyAlterDocumentContentEvent, registerSubmitAlterDocumentContentEvent, registerDocumentBuilderOpeningEvent, registerDocumentBuilderSaveCustomEvent.


Namespace: arender.zoomJSAPI

MethodParametersDescription
askZoomIn()Zooms in one step
askZoomOut()Zooms out one step
askZoomFullWidth()Fits the page width to the viewer
askZoomFullHeight()Fits the page height to the viewer
askZoomFullPage()Fits the whole page in the viewer
askZoomInZone(x, y, w, h)x, y, w, h: intZooms into a specific rectangular region (pixel coordinates)

Namespace: arender.zoomGlassJSAPI

MethodParametersDescription
toggle()Shows or hides the magnifying glass overlay
updateZoom(zoom)zoom: floatSets the magnification ratio of the glass
updatePosition(x, y, w, h)x, y, w, h: floatMoves the glass to a position (relative page coordinates)

Namespace: arender.rotateJSAPI

MethodParametersDescription
askRotateCurrentPageLeft()Rotates the current page 90° counter-clockwise
askRotateCurrentPageRight()Rotates the current page 90° clockwise
askRotateAllPageLeft()Rotates all pages 90° counter-clockwise
askRotateAllPageRight()Rotates all pages 90° clockwise
askRotatePage(pageNumber, documentId, rotation, clockwise)pageNumber: int, documentId: string, rotation: int (90/180/270), clockwise: booleanRotates a specific page by an explicit angle

Callback: registerNotifyPageRotatedEvent(cb), signature: cb(documentId, pageNumber, rotation).


Namespace: arender.fullScreenJSAPI

MethodDescription
askOpenFullScreen()Enters full-screen mode
askCloseFullScreen()Exits full-screen mode

Namespace: arender.searchJSAPI

MethodParametersDescription
askSearchTextNext(text)text: stringSearches forward for the next occurrence (case-insensitive)
askSearchTextPrevious(text)text: stringSearches backward for the previous occurrence
askAdvancedSearchText(text, caseSensitive, accentSensitive, regex, scope, annotations, postAction)see belowFull-featured search with options
clearSearchResults()Clears all highlighted search results

askAdvancedSearchText parameters:

ParameterTypeValues
textstringSearch term or regular expression
caseSensitiveboolean
accentSensitiveboolean
regexbooleanTreat text as a regex
scopestring'CurrentPage', 'AllPages', 'AllDocuments' (default)
annotationsstring'WithAnnotations', 'WithoutAnnotations' (default), 'OnlyAnnotations'
postActionstring'NONE' (default), 'REDACT', 'HIGHLIGHT'

Example: search and highlight all occurrences

arender.jsapi.getSearchJSAPI().askAdvancedSearchText(
'confidential', false, false, false,
'AllDocuments', 'WithoutAnnotations', 'HIGHLIGHT'
);

Namespace: arender.showPrintDialogJSAPI

MethodDescription
askShowPrintDialog()Opens the print dialog
askPrintAllDocumentPages()Prints all pages without opening a dialog

Namespace: arender.downloadDocumentJSAPI

MethodDescription
askDownloadDocumentPDF()Downloads the current document as PDF
askDownloadDocumentNonPDF()Downloads the document in its non-PDF form
askDownloadDocumentSource()Downloads the original source file
askDownloadAllDocuments()Downloads all open documents as a single PDF
askDownloadAllSourcesDocuments()Downloads all open documents as originals (ZIP)
askDownloadAnnotations()Downloads the document with annotations burned in
askDownloadWithFDFAnnotations()Downloads the document with FDF annotations embedded
askDownloadFDFAnnotations()Downloads the FDF annotations file only
askDownloadWithAnnotations()Downloads a copy with annotations overlaid
askDownloadWithRedact()Downloads the document with redactions applied
askDownloadCompareResultDocument()Downloads the comparison result document

Namespace: arender.genericNotificationJSAPI

MethodParametersDescription
askNotification(message, type)message: string, type: 'SEVERE'|'WARNING'|'INFO'Displays a toaster notification

Namespace: arender.thumbnailsJSAPI

MethodParametersDescription
showNavigator()Shows the left-side document navigator
hideNavigator()Hides the document navigator
resetNavigator()Resets the navigator to its default visible state
expandNavigator(width)width: intExpands the navigator to a given pixel width
reduceNavigator(width)width: intReduces the navigator to a given pixel width

Namespace: arender.documentLayout

MethodParametersDescription
getDocumentLayout(documentId, onLayout, onError)documentId: string, onLayout: function(layout), onError: function(docId, message)Retrieves a fully resolved layout tree (all children expanded)
getShallowDocumentLayout(documentId, onLayout, onError)documentId: string, onLayout: function(layout), onError: function(docId, message)Retrieves the layout with children as stubs (IDs only)

The layout object passed to the callback has the following properties:

PropertyTypeDescription
documentIdstringDocument ID
documentTitlestringHuman-readable title
pageDimensionsarrayArray of {width, height, rotation} per page
childrenarrayChild layouts (for container documents)
exceptionstringError message if this child could not be resolved

Example:

arender.jsapi.getDocumentLayout().getDocumentLayout(
arender.jsapi.getMasterDocumentId(),
function(layout) {
console.log(layout.documentTitle, layout.pageDimensions.length, 'pages');
},
function(docId, msg) { console.error(msg); }
);

Namespace: arender.documentCompare

MethodParametersDescription
doComparisonFromStringUUID(leftId, rightId)leftId, rightId: stringStarts a visual comparison between two documents and opens the result in multi-view
closeAllMultiView()Closes all multi-view panels

Example:

arender.jsapi.getDocumentCompareJSAPI()
.doComparisonFromStringUUID(docIdA, docIdB);

Namespace: arender.annotationJSAPI

The annotation module loads asynchronously. Use onAnnotationModuleReady to safely access it:

arender.jsapi.onAnnotationModuleReady(function(annotApi) {
annotApi.save();
});
MethodParametersDescription
addAnnotation(documentId, type, x, y, w, h, page, color, opacity)see belowAdds an unsaved annotation at the given position
save()Saves all dirty (unsaved) annotations
refresh()Reloads annotations from the server (unsaved changes are kept)
hasDirtyAnnotations()Returns true if there are unsaved annotations
getDestinationTypes()Returns the available hyperlink destination types
getActionTypes()Returns the available hyperlink action types
getPropertyFromDestination(dest, prop)dest, prop: stringExtracts a property from a destination descriptor
getPropertyFromAction(action, prop)action, prop: stringExtracts a property from an action descriptor
createDocLink(pageNumber)pageNumber: intStarts a doc-link creation on the given page

addAnnotation parameters:

ParameterTypeDescription
documentIdstringTarget document ID
typestringAnnotation type (e.g. 'StickyNote', 'Highlight', 'FreeText')
x, y, w, hintPosition and size in page units
pageint0-based page number
colorstringCSS color string
opacityfloat0.0 to 1.0

Callbacks:

MethodCallback signatureDescription
registerNotifyAnnotationAddedEvent(cb)cb(documentId, annotationJson, isFromDocumentParsing)Fires when an annotation is added
registerNotifyAnnotationDeletedEvent(cb)cb(documentId, annotationJson)Fires when an annotation is deleted
registerNotifyAnnotationUpdatedEvent(cb)cb(documentId, annotationJson)Fires when an annotation is updated
registerFollowLinkHandler(cb)cb(documentId, page, destination, action, id)Fires when a hyperlink is clicked
registerDocLinkTextSelectionEvent(cb)cb()Fires when the user completes a doc-link text selection
registerDocLinkStateChange(cb)cb()Fires when the doc-link mode state changes
registerCloseMultiView(cb)cb()Fires when all multi-view panels are closed

Namespace: arender.screenSplitJSAPI

MethodParametersDescription
askOpenAsNewDocument(documentId)documentId: stringOpens an already-loaded document as a second pane in split-screen