API Reference

Table of Contents

API

constants

constants.PageProgression

Enum PageProgression represents page progression direction. PageProgression has members, LTR and RTL.

constants.PageSide

Enum PageSide represents page side. PageSide has members, LEFT and RIGHT.

constants.ReadyState

Enum ReadyState represents viewer ready state. ReadyState has members, LOADING, INTERACTIVE and COMPLETE.

plugin

plugin.registerHook(name, fn)

Register a function to a hook with the specified name. The registered function is called at appropriate timings by the core code. Arguments passed to the function depend on the hook. When multiple functions are registered, they are called by the order in which they are registered.

Parameters

plugin.removeHook(name, fn)

Remove a function already registered to the specified name. Note that even if the same function are registered multiple times, this method removes only the first one.

Parameters

profile

profile.profiler.registerStartTiming(name, timestamp)

Registers start timing of some event.

Parameters

profile.profiler.registerEndTiming(name, timestamp)

Registers end timing of some event.

Parameters

profile.profiler.printTimings()

Log registered timings (start/end/duration). All values are printed in ms unit.

profile.profiler.disable()

Disable profiling.

profile.profiler.enable()

Enable profiling.

viewer

new viewer.Viewer(settings, options)

Vivliostyle Viewer class. Creates Viewer.

Parameters

viewer.PageViewMode

Enum PageViewMode. PageViewMode has members, SINGLE_PAGE, SPREAD and AUTO_SPREAD.

viewer.ZoomType

Enum ZoomType. ZoomType has only one member, FIT_INSIDE_VIEWPORT.

Classes

Viewer

Viewer.addListener(type, listener)

Add a listener function, which is invoked when the specified type of event is dispatched.

Parameters

Viewer.getCurrentPageProgression()

Returns the current page progression of the viewer. If no document is loaded, returns null.

Returns

PageProgression

Viewer.getPageSizes()

Returns

Array<{width: number, height: number}>

Viewer.isTOCVisible()

Returns true if TOC is visible, false if hidden, null if TOC is unavailable

Viewer.loadDocument(singleDocumentOptions, documentOptions, viewerOptions)

Load an HTML or XML document(s).

Parameters

Viewer.loadPublication(pubURL, documentOptions, viewerOptions)

Load a EPUB/WebPub publication.

Parameters

Viewer.navigateToInternalUrl()

Navigate to the specified internal URL.

Viewer.navigateToPage()

Navigate to the specified page.

Viewer.queryZoomFactor(type)

Returns zoom factor corresponding to the specified zoom type.

Parameters
Returns

number

Viewer.removeListener(type, listener)

Remove an event listener.

Parameters

Viewer.setOptions(options)

Set ViewerOptions to the viewer.

Parameters

Viewer.showTOC(opt_show, opt_autohide)

Show or hide TOC box

Parameters

TypeDefs

DocumentOptions

Options for the displayed document.

SingleDocumentOptions

Options for a single source document. SingleDocumentOptions is the object that has members below, or otherwise string that represents url.

ViewerSettings

Viewer settings that must be passed to Viewer’s constructor.

ViewerOptions

Viewer options that can be set after the Viewer object is constructed.

print

printHTML

Allows page-layouting using the vivliostyle for printing within a website without destroying the original layout

import { printHTML } from "@vivliostyle/core";

const htmlDoc = `<!doctype html>
<html>
    <head>
        <style>
        ... Add your CSS code here ...
        </style>
    </head>
    <body>
        ... Add your HTML code here ...
    </body>
</html>`;

const config = {
  title: "My printed page",
  printCallback: (iframeWin) => iframeWin.print(), // optional: only needed if calling something other than window.print() for printing.
};

printHTML(htmlDoc, config);