Code Monkey home page Code Monkey logo

svelte-pdfjs's Introduction

svelte-pdfjs

A wrapper around Mozilla's PDFJS renderer. Only cares about loading and showing the PDF and nothing else, all the fancy stuff such as styling the viewer is left up to the consumer. Still in early stages so feel free to create an issue or a PR for any bugs that you find, any improvements or feature requests.

Usage

You'll have to install pdfjs-dist and provide a worker to the Document component through svelte's context. For vite/sveltekit users a convenience function is exported through svelte-pdfjs/utils/vite which takes care of browser checks, resolving the url to the worker, setting the context and cleaning up when the component is destroyed.

See src/routes/+page.svelte and src/routes/+layout.svelte Demo

SSR

For now this package cannot be used with SSR, contributions to improve in that area are more than welcome. Because of how pdfjs-dist is packaged, there is an eval which prevents bundlers from properly minifying whatever chunk it ends up in. To get around it, you can patch your installation of pdfjs-dist such that all instances of _is_node.isNodeJs are replaced with false since those parts aren't going to be used anyway.

TODOs:

  • Text layer rendering
  • SvelteKit compatibility
  • SVG renderer
  • Annotation layer
  • Error handling
  • Expose more stuff

License

MIT

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.