Coder Social home page Coder Social logo

netless-app-pdfjs's Introduction

@netless/app-pdfjs

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

Install

npm add @netless/app-pdfjs

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) // the app is named 'PDFjs'
  3. Add this app after joinning room.

    fastboard.manager.addApp({
      kind: 'PDFjs',
      options: {
        title: 'a.pdf',
        scenePath: '/pdf/paper' // ! This is required.
      },
      attributes: {
        src: 'https://cdn.jsdelivr.net/gh/mfogel/polygon-clipping/paper.pdf'
      }
    })

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/

Uncaught SyntaxError / Uncaught ReferenceError

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

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.

License

MIT @ netless

netless-app-pdfjs's People

Contributors

hyrious avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.