Coder Social home page Coder Social logo

vue-pdf-optimization's Introduction

vue-pdf-optimization

PDF.js is very advanced JS library for parsing and displaying PDF files by Mozilla. This project aims to provide simple and lightweight Vue.js component, that downloads library files lazily from cdn with minimal setup.

Similar projects:

  • vue-pdf - includes PDF.js files into your bundle with webpack. Sometimes this may be undesirable because:
    • it may require additional webpack configuration
    • webpack processing can lead to issues
    • latest webpack has a bug in development mode with worker files
    • it will increase bundle size (pdf.js viewer + worker = about 800 kb) and build time.

Install

yarn add vue-pdf-optimization
# or
npm install vue-pdf-optimization --save

Usage

在根页面引入cdn

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <title>vue-pdf-cdn</title>
  </head>
  <body>
    <noscript>
      <strong>We're sorry but vue-pdf-cdn doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div>
    <script  src="https://unpkg.com/pdfjs-dist@latest/build/pdf.min.js"></script>
    <!-- built files will be auto injected -->
  </body>
</html>
<template>
    <pdf
        v-for="i in numPages"
        :key="i"
        :src="src"
        :num="i"
    />
</template>

<script>
import pdf from 'vue-pdf-optimization'

export default {
  components: {
    pdf
  },
  created() {
        const loadingTask = window.pdfjsLib.getDocument('pdf地址')
        this.src = loadingTask.promise
        this.src.then( pdf => {
            this.numPages = pdf.numPages
        })
  }
}
</script>

Props

  • src - URL of PDF file to load and display

Events

  • @status - triggered when status update happens (library initialized, pdf downloaded, etc.). Provides string describing status.
  • @error - triggered when error happens. Provides error message.
  • @loading - triggered when loading status changes. Provides boolean (true/false).

vue-pdf-optimization's People

Contributors

clariokids avatar leo-buneev avatar

Watchers

 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.