Vivliostyle Viewer User’s Guide

Vivliostyle Viewer is a web application displaying and typesetting HTML+CSS documents.

How to use

To use the Vivliostyle Viewer in a local environment, start a web server by following the instructions described in the README.md (read online) attached to the distribution package.

You can also use the public online Vivliostyle Viewer, https://vivliostyle.github.io/vivliostyle.js/viewer/vivliostyle-viewer.html, that has always been updated to the latest development version.

The vivliostyle-viewer.html in the viewer folder is the main file of Vivliostyle Viewer.

When you open Vivliostyle Viewer without specifying parameters, an “Input a document URL” box and the following usage description is displayed:

Supported document types:

  • (X)HTML document, with CSS for paged media
  • Web publication (a collection of HTML documents): specify URL of the primary entry page or manifest file.
  • Unzipped EPUB: specify URL of OPF file or top directory of the unzipped EPUB files.

Notes:

  • GitHub and Gist URLs can be directly specified. Vivliostyle loads raw github/gist content when such URL is specified.
  • ⚠️Mixed Content (“http:” URL is specified to “https:” Vivliostyle Viewer) is usually blocked by browser.
  • ⚠️Cross-Origin (request to different domain) is usually blocked by browser unless the server is configured to allow Cross-Origin Resource Sharing (CORS).

URL parameter options:

  • #b=<document URL> or #x=<document URL>
    • #b= Book view. When (X)HTML document URL is specified, the URL is treated as primary entry page’s, and a series of HTML documents linked from the manifest or TOC (Table of Contents, e.g. marked up with <nav role="doc-toc">) are automatically loaded.
    • #x= (X)HTML document is simply loaded. Multiple documents can be specified as #x=<1st HTML>&x=<2nd HTML>...
  • &spread=[true | false | auto]
    • true: Spread view
    • false: Single page view
    • auto: Auto spread view (default)
  • &renderAllPages=[true | false]
    • true: for Print (all pages printable, page count works as expected)
    • false: for Read (quick loading with rough page count)
  • &style=<additional external style sheet URL>
  • &userStyle=<user style sheet URL>

Options can also be set in the Settings panel.

Specifying HTML documents to be displayed in Vivliostyle Viewer

To display an HTML file in the Vivliostyle Viewer, place the file (and CSS or image files read from the file) somewhere which the web server can read (if you start the web server following the above instructions in case of local environment, it is the folder generated by unzipping the distribution package), then open the following URL in your browser:

⟨Vivliostyle Viewer URL⟩#x=⟨URL of the file to be displayed (relative to the Vivliostyle Viewer)⟩

Note: If you want to display a document from a domain which is different from the domain of the Vivliostyle Viewer itself, it is possible that it cannot be displayed, depending on the web server that serves the document file. You need to configure CORS (Cross-Origin Resource Sharing) on the server.

Note: Since Vivliostyle Viewer uses an online JavaScript library (MathJax) to display mathematics (supports MathML and TeX formats), the internet connection is required when the document contains mathematics.

Example: If you want to display a HTML file samples/wood/index.html:

Input the document file path (or URL) in the text box; the Vivliostyle Viewer URL of the document is displayed below:

To display EPUB

You can display unzipped EPUB files with the Vivliostyle Viewer. In this case, use the following parameter:

#b=⟨URL of the unzipped EPUB folder (relative to the Vivliostyle Viewer)⟩

Example: If you want to display an unzipped EPUB folder samples/niimi/:

Input the EPUB folder path (or URL) in the text box; the Vivliostyle Viewer URL of the EPUB document is displayed below:

An example of displaying unzipped EPUB on GitHub:

To display Web publications

You can display Web publications (a collection of HTML documents) with the Vivliostyle Viewer. In this case, use the following parameter:

#b=⟨URL of the primary entry page HTML document or manifest file (relative to the Vivliostyle Viewer)⟩

For the format of Web publication manifest, W3C draft Web Publications and Readium Web Publication Manifest are supported.

When Web publication manifest does not exist, and there are links to other HTML documents in the table of contents in the specified HTML document, those documents are loaded automatically. Vivliostyle treats HTML elements that match the following CSS selector as a table of contents element: [role=doc-toc], [role=directory], nav li, .toc, #toc

An example of displaying publications composed of multiple HTML documents published on the Web:

To specify page spread view mode

Vivliostyle Viewer displays pages automatically with spread view mode when the width of the view area is wide (1.45 times the height or more). To change the spread view mode, append one of the following to the URL:

&spread=true (always spread view)
&spread=false (always single page view)
&spread=auto (auto spread view = default)

You can also change the page view mode in the Vivliostyle Viewer's setting panel (open by clicking the [Setting] icon in the upper right corner of the viewer).

To specify additional style sheets

To use additional style sheets (CSS files) in addition to the style sheets specified in the HTML file, append the following to the URL:

&style=⟨style sheet URL (relative to the Vivliostyle Viewer)⟩

The style sheets specified in this way are treated as author style sheets, as if they are specified in the HTML file at very last, and can override styles of other style sheets according to the CSS cascading rules.

On the other hand, you can also specify user style sheets (cannot override styles of author style sheets unless specifying !important) as follows:

&userStyle=⟨user style sheet URL (relative to the Vivliostyle Viewer)⟩

Using multiple &style= and/or &userStyle= you can specify as many style sheets as needed.

You can also use data URL. For example:

&userStyle=data:,html{writing-mode:vertical-rl}

User style can also be set in the User Style Preferences in the settings panel. You can check the CSS in the CSS Details box.

An example in which user style settings are added from the settings panel to the document on the Web:

When setting styles from the settings panel like this example, the CSS code of the styles set from option items in the settings panel is generated between the comments /*<viewer>*/ and /*</viewer>*/ in the user style CSS that are displayed in the CSS Details box. You can add your own CSS code to it. In this example, page header and footer are added.

How to Print/Save as PDF from Vivliostyle Viewer

Use your browser’s print/save as PDF feature. For example, to save as PDF with Google Chrome, select Print from menu, set Destination to “Save as PDF”, check “Background graphics”, and “Save” to PDF.

Note: When you print all pages of a document, check that Render All Pages is On in the setting panel. When this is Off, only the pages that have already been displayed can be printed, and the page number will not be output correctly.

CSS features supported by Vivliostyle

Supported CSS features are described in Features supported by Vivliostyle.

Other documentation

You can find other documentation at Vivliostyle Documentation

Samples

Fixed page size samples

Japanese novel “Gon, the Little Fox”

Page/Spread ViewRaw HTMLSource

Japanese multi-column magazine “Mt. Shirouma”

Page/Spread ViewRaw HTMLSource

Web fonts sample “Wood Engraving”

Variable page size samples

“The Malay Archipelago”

Page/Spread ViewRaw HTMLSource

Japanese, Horizontal writing mode “Takasebune”

Page/Spread ViewRaw HTMLSource

Japanese, Vertical writing mode “Takasebune”

Page/Spread ViewRaw HTMLSource

Adaptive Layout

“Apollo 8”

Page ViewSpread ViewRaw HTMLSource

“Candle”

Page ViewSpread ViewRaw HTMLSource

“Advanced Adaptive Layout”

Page ViewSpread ViewRaw HTMLSource

(from Peter Sorotokin's Adaptive Layout)

  • Page/Spread View for auto spread paginated view with online Vivliostyle Viewer.
  • Page View for single page paginated view with online Vivliostyle Viewer.
  • Spread View for spread paginated view with online Vivliostyle Viewer.
  • Raw HTML for normal HTML view.
  • Source for source files, HTML+CSS etc., on GitHub.

Other samples

You can find other samples at Vivliostyle Samples.