Skip to main content
Version: v2023.24.0

Opening a document

Opening documents​

  • Object: getARenderJS()
FunctionDescriptionArguments
loadDocument(url, callback)

Loads a document providing an URL. It will provide an ARender Id back.

Note: This is purely a server-side operation, asynchronous at client side.

url: the URL to open;
callback: the callback function to call when the Id is provided by the server.

openDocument(id, resetUI)Opens a document with the id.
If the value of resetUI is true, or if it is not provided, the UI resets to its initial state; otherwise, the UI remains unchanged.
id: ARender id
resetUI: Reset or not the UI
askChangePage(type, index)Changes the current page.

type: 'Relative', 'Index' or 'Absolute';
index: -1 or 1 for 'Relative' or 'Absolute', otherwise the page number.

askChangePage(type, index, position, centerPosition)

Changes the current page and goes to a position in it. The position is centered in the view, unless centerPosition is false: it is then placed at the top of the view, as an internal hyperlink click does.

Note: centerPosition is available since 2023.24.0.

type, index: as above;
position: a position built by newPageRelativePosition();
centerPosition: optional, true by default.

newPageRelativePosition(x, y, w, h)Builds a position rectangle for askChangePage(), in page points (1/72 inch) from the top-left corner of the page.x, y, w, h: the coordinates, width and height of the rectangle, in page points.
enablePDFDocumentHyperlinks(boolean)Activate/de-activate the internal hyperlinks of a document.boolean: Load internal hyperlinks of a document if true, unload them otherwise.
disallowClickOnHyperlinks(boolean)Allow/disallow clicks on a document hyperlink for ARender.boolean: if true, disallow internal hyperlinks of a document, allow them otherwise.
// Loads the PDF reference document
getARenderJS().loadDocument(
"loadingQuery?url=http://www.arender.fr/pdf/pdf/PDFReference15_v5.pdf",
function (id) {
getARenderJS().openDocument(id);
}
);
// Move to page 24 (note that page index is starting at 0. So page 1 has index 0)
getARenderJS().askChangePage("Index", 23);
// Move to last page
getARenderJS().askChangePage("Absolute", 1);

Coordinates are page points, not fractions of the page: y = 421 is the middle of an A4 page, which is 842 points high. A PDF destination counts its top from the bottom of the page, so convert it with y = pageHeight - top. A centered change aims at the center of the rectangle: with w = h = 0, it aims at x, y.

var position = getARenderJS().newPageRelativePosition(0, 421, 0, 0);
// Center the middle of the third page in the view
getARenderJS().askChangePage("Index", 2, position);
// Put the middle of the third page at the top of the view
getARenderJS().askChangePage("Index", 2, position, false);

In the example above, loadDocument returns an ID (in the form of a string starting with "b64_") that will allow manipulation of the document in the ARender view.

openDocument is then called with the ID of the loaded document as a parameter, thereby displaying the document in question.

Multiple document opening​

ARender provides the possibility to open several documents by loading a list of documents which will be provided via JSON in order to define the tree structure. All the technical details can be found here

Get opening document time​

  • Object: getARenderJS()
FunctionDescriptionArguments
registerFirstPageLoaded(notifyFirstPageLoadedHandler)Register a hook to get the first page loaded timecallback: the callback function to call
getARenderJS().registerFirstPageLoaded(function(documentId, time) {
console.error("DocumentId = " + documentId + ", time = " + time);
});