npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pdftron/webviewer-reading-mode

v1.0.8

Published

WebViewer reading mode for viewing PDF files.

Downloads

2,423

Readme

webviewer-reading-mode

A node module to view PDF in reading mode. It will convert the given PDF file to html, and then render it in given viewport.

Installation

npm i @pdftron/webviewer-reading-mode

Usage

1. Import

In standalone HTML page

Import dist/webviewer-reading-mode.js into your page.

Using NPM

import WebViewerReadingMode from "@pdftron/webviewer-reading-mode";

2. Call the 'initialize' API to initialize WebViewerReadingMode

Example:

/**
 * Initialize a new instance of WebViewerReadingMode and return it.
 * @param {PDFNet} pdfNet The PDFNet lib.
 */
this.wvReadingMode = WebViewerReadingMode.initialize(PDFNet);

3. Call the 'render' API to render PDF in reading mode

Example:

/**
 * Render ReadingModeComponent in the given viewer element.
 * @param {Promise<PDFDoc>} doc The PDFDoc object of the PDF file to render.
 * @param {Element} viewerElement The element that ReadingModeComponent is rendered in.
 * @param {object} options Render options. Note: All options are optional.
 * @param {function} options.pageNumberUpdateHandler Function to handle page number update event.
 * @param {number} options.pageNum The page number to go to after initialization. (1-indexed) If not set, will default to 1.
 * @param {boolean} options.isSinglePageMode Default: True. True will render in single-page mode, false will render in continuous-page mode.
 * @param {function} options.pageCountHandler Function to handle page count.
 * @param {function} options.editStyleHandler Function to handle Edit Style button click event.
 */
// Render a file from url in single-page mode, and go to the 3rd page after initial load.
this.wvReadingMode.render(
  PDFNet.PDFDoc.createFromURL(url),
  document.getElementById('web-viewer'),
  {
    pageNumberUpdateHandler: (pageNum) => { /* Handle page number updated */ },
    pageNum: 3,
    isSinglePageMode: true,
    pageCountHandler: (pageCount) => { /* Handle page count updated */ },
    editStyleHandler: (annotColor, annotType, setAnnotColor, doneSetAnnotColor) => { /* Handle Edit Style button click event */ }
  }
);

4. Call the 'goToPage' API to jump to specific page

Example:

/**
 * Go to the page with given page number.
 * @param {number} pageNum The page number to go to.
 */
// Go to 5th page
this.wvReadingMode.goToPage(5);

5. Call the 'setZoom' API to zoom in/out

Example:

/**
  * Set the zoom level for all pages.
  * @param {number} zoomLevel The zoom level to set.
  */
// Zoom to 150%
this.wvReadingMode.setZoom(1.5);

6. Call the 'setAddAnnotConfig' API to set configuration for adding new annotation

Example:

/**
  * Set the configuration for adding new annotation.
  * @param {object} config Add annotation config. { type: AnnotationType, color: string }
  */
// Set the current add annotation configuration to be Highlight with red color.
this.wvReadingMode.setAddAnnotConfig({ type: WebViewerReadingMode.Highlight, color: '#ff0000' });

7. Call the 'unmount' API to unmount ReadingModeComponent

Example:

/**
 * Unmount ReadingModeComponent from the current viewerElement.
 */
this.wvReadingMode.unmount();

Running samples

Clone the project from https://github.com/XodoDocs/webviewer-reading-mode.git. Go to the project directory and run:

npm i
npm run build
npm start

Then it will open the browser redirect to the samples page.