CoreViewer
addListener(type, listener)getCurrentPageProgression()getPageSizes()isTOCVisible()loadDocument(singleDocumentOptions, documentOptions, viewerOptions)loadPublication(pubURL, documentOptions, viewerOptions)navigateToInternalUrl()navigateToPage()queryZoomFactor(type)removeListener(type, listener)setOptions(options)showTOC(opt_show, opt_autohide)constants.PageProgressionEnum PageProgression represents page progression direction.
PageProgression has members, LTR and RTL.
constants.PageSideEnum PageSide represents page side.
PageSide has members, LEFT and RIGHT.
constants.ReadyStateEnum ReadyState represents viewer ready state.
ReadyState has members, LOADING, INTERACTIVE and COMPLETE.
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.
name (string) β Name of the hook.fn (function) β Function to be registered to the hook.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.
name (string) β Name of the hook.fn (function) β Function to be removed from the hook.profile.profiler.registerStartTiming(name, timestamp)Registers start timing of some event.
name (string) β Name of event.timestamp (number, optional) β Used as the actual timestamp of the event if specified, instead of βnowβ.profile.profiler.registerEndTiming(name, timestamp)Registers end timing of some event.
name (string) β Name of event.timestamp (number, optional) β Used as the actual timestamp of the event if specified, instead of βnowβ.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.
new CoreViewer(settings, options)Vivliostyle CoreViewer class. Creates CoreViewer.
settings (CoreViewerSettings)options (CoreViewerOptions, optional)PageViewModeEnum PageViewMode.
PageViewMode has members, SINGLE_PAGE, SPREAD and AUTO_SPREAD.
ZoomTypeEnum ZoomType.
ZoomType has only one member, FIT_INSIDE_VIEWPORT.
CoreViewerCoreViewer.addListener(type, listener)Add a listener function, which is invoked when the specified type of event is dispatched.
type (string) β Event type.listener (function) β Listener function.CoreViewer.getCurrentPageProgression()Returns the current page progression of the viewer. If no document is loaded, returns null.
CoreViewer.getPageSizes()Array<{width: number, height: number}>
CoreViewer.isTOCVisible()Returns true if TOC is visible, false if hidden, null if TOC is unavailable
CoreViewer.loadDocument(singleDocumentOptions, documentOptions, viewerOptions)Load an HTML or XML document(s).
singleDocumentOptions (SingleDocumentOptions |
Array<SingleDocumentOptions>) |
documentOptions (DocumentOptions, optional)viewerOptions (CoreViewerOptions, optional)CoreViewer.loadPublication(pubURL, documentOptions, viewerOptions)Load a EPUB/WebPub publication.
pubURL (string)documentOptions (DocumentOptions, optional)viewerOptions (CoreViewerOptions, optional)CoreViewer.navigateToInternalUrl()Navigate to the specified internal URL.
CoreViewer.navigateToPage()Navigate to the specified page.
CoreViewer.queryZoomFactor(type)Returns zoom factor corresponding to the specified zoom type.
type (ZoomType)number
CoreViewer.removeListener(type, listener)Remove an event listener.
type (string) β Event type.listener (function) β Listener function.CoreViewer.setOptions(options)Set CoreViewerOptions to the viewer.
options (CoreViewerOptions)CoreViewer.showTOC(opt_show, opt_autohide)Show or hide TOC box
opt_show (boolean) - If true show TOC, false hide TOC. If null or undefined toggle TOC.opt_autohide (boolean) - If true, automatically hide when click TOC itemDocumentOptionsOptions for the displayed document.
documentObject (Document, optional) β Document object for the document. If provided, it is used directly without parsing the source again.fragment (string, optional) β Fragmentation identifier (EPUB CFI) of the location in the document which is to be displayed.authorStyleSheet (Array<string>, optional) β An array of author style sheets to be injected after all author style sheets referenced from the document. A single stylesheet may be a URL of the style sheet or a text content of the style sheet.userStyleSheet (Array<string>, optional) β An array of user style sheets to be injected. A single stylesheet may be a URL of the style sheet or a text content of the style sheet.SingleDocumentOptionsOptions for a single source document.
SingleDocumentOptions is the object that has members below, or otherwise string that represents url.
url (string) β URL of the document.startPage (number, optional) β If specified, the page page-based counter is set to the specified value on the first page of the document. It is equivalent to specifying counter-reset: page [specified value - 1] on that page.skipPagesBefore (number, optional) β If specified, the page page-based counter is incremented by the specified value before updating page-based counters on the first page of the document. This option is ignored if startPageNumber option is also specified.CoreViewerSettingsCoreViewer settings that must be passed to CoreViewerβs constructor.
viewportElement (HTMLElement, required) β An element used as the viewport of the displayed contents.userAgentRootURL (string, optional) β URL of a directory from which viewer resource files (under resources/ directory in the source repository) are served.window (Window, optional) β Window object. If omitted, current window is used.debug (boolean, optional) β Debug flag.CoreViewerOptionsViewer options that can be set after the Viewer object is constructed.
autoResize (boolean, optional) β Run layout again when the window is resized. default: truefontSize (number, optional) β Default font size (px). default: 16pageBorderWidth (number, optional) β Width of a border between two pages in a single spread (px). Effective only in spread view mode. default: 1renderAllPages (boolean, optional) β Render all pages at the document load time. default: truepageViewMode (PageViewMode, optional) β Page view mode (singlePage / spread / autoSpread). default: singlePagezoom (number, optional) β Zoom factor with which pages are displayed. default: 1fitToScreen (boolean, optional) β Auto adjust zoom factor to fit the screen. default: falsedefaultPaperSize ({width: number, height: number}, optional) β Default paper size in px. Effective when @page size is set to auto. default: undefined (means the windows size is used as paper size).printHTMLAllows 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);