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

@netless/app-pdfjs

v0.1.4

Published

Netless App for viewing raw PDF files, using PDF.js

Downloads

11

Readme

@netless/app-pdfjs

A Netless App that renders PDF files with PDF.js.

Install

Usage

[!IMPORTANT] This app only implements viewing PDF files.
It does not support dispatchDocsEvent() nor export PDF.

  1. Get a static URL pointing to the PDF file.

    This package only synces the URL for each client to download the PDF. You have to obtain a static URL to the file first to continue. For example, you can use an OSS to achieve this.

  2. Register this app before joinning room.

    import { register } from "@netless/fastboard"
    import { install } from "@netless/app-pdfjs"
    
    install(register, options) // the app is named 'PDFjs'
  3. Add this app after joinning room.

    fastboard.manager.addApp({
      kind: 'PDFjs',
      options: {
        title: 'a.pdf', // ! Required. Window title.
        scenePath: '/pdf/paper' // ! Required. Make sure it starts with `/` and not ends with `/`.
      },
      attributes: {
        prefix: "https://white-cover.oss-cn-hangzhou.aliyuncs.com/flat/", // ! Required.
        taskId: "b444a180c2f44a409a4d081e8f1a6d5f", // ! Required.
      }
    })

    You can get the prefix and taskId from the conversion response JSON.

Troubleshooting

Failed to fetch pdf.min.mjs

This package downloads the latest PDF.js release from jsDelivr:
https://cdn.jsdelivr.net/npm/pdfjs-dist@latest/build/

To alter this URL or choose a different version, set the app option:

install(register, {
  appOptions: {
    pdfjsLib: 'https://cdn.jsdelivr.net/npm/pdfjs-dist@latest/build/pdf.min.mjs',
    workerSrc: 'https://cdn.jsdelivr.net/npm/pdfjs-dist@latest/build/pdf.worker.min.mjs'
  }
})

If the URL is blocked by your CSP, you have to add them to your script-src policy:

Content-Security-Policy: script-src https://cdn.jsdelivr.net/

Note: If you want to load PDFs on demand (without having to download the entire PDF before rendering), you need to expose the 'Accept-Ranges' headers on your stored OSS. If our library cannot obtain this header, it will not make segmented requests.

TypeError: Promise.withResolvers is not a function

PDF.js uses Promise.withResolvers(), which is a brand new feature in JavaScript. In case your target environment does not support this, you need to add the following code to the first line of pdf.min.mjs and pdf.worker.min.mjs to resolve this issue.

if (typeof Promise.withResolvers === 'undefined') {
  Promise.withResolvers = function () {
    let resolve, reject
    const promise = new Promise((res, rej) => {
      resolve = res
      reject = rej
    })
    return { promise, resolve, reject }
  }
}

For convenience, you can run node ./scripts/patch.mjs in this repo to generate patched pdf.min.mjs and pdf.worker.min.mjs. The 2 files will be placed at the dist folder.

Uncaught SyntaxError / Uncaught ReferenceError

This package only targets modern browsers that support native ES modules.

A certain PDF file opens exceptionally slowly, even several times slower than smaller PDFs.

Most PDF files are designed for easy transmission, allowing us to render a single page by requesting a portion of the file through Range requests. However, a few PDF files require a complete download before they can be rendered. You can check the browser's requests to confirm if the slow rendering of the first page is due to the complete download of a PDF file. If so, you need to use qpdf to convert the PDF into a structure that is easier to transmit.

What should I do if the OSS I entered in the Agora Console is private?

You can add a new property urlInterrupter to the second parameter options when calling register. This property is a function that returns a publicly accessible address by passing in the URL.

PDF Rendering Issue

As the package name implies, it uses PDF.js to render the file. It is possible that PDF.js has a bug when rendering some files. Please raise an issue there to ask for help.

Changelog

License

MIT @ netless