0.0.1-security β€’ Published 2 years ago

bsd-pdf v0.0.1-security

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

BSD-PDF

Render PDF files on Vue pages using pdf.js, supporting text rendering, lazy loading, paging, scaling, and printing.

Install

npm install bsd-pdf --save

Quick Start

import bsdPdf from 'bsd-pdf'
import 'bsd-pdf/package/bsd-pdf.css'
Vue.use(bsdPdf)

// OR
import bsdPdf from 'bsd-pdf'
import 'bsd-pdf/package/bsd-pdf.css'
export default {
  // ...
  components: {
    bsdPdf
  }
  // ...
}

Example

Note: the use of print, need to cooperate with the print style.

<template>
  <bsd-pdf ref="pdf" @on-success="load" @on-pagerender="pagerender" @on-scroll="scroll" :filePath="src">
    <template slot="header">
      pdf-src:<input type="text" v-model.lazy="src" @change="fileChanged">
    </template>
    <template slot="footer">
      <button :disabled="currentNum<=1" @click="pre">pre</button>
      <input type="number" :min="1" :max="pageNum" v-model.number="currentNum" @change="pageChange(currentNum)">
      <button :disabled="currentNum>=pageNum" @click="next">next</button>
      <select v-model="scale" @change="setScale">
        <option value="auto">auto</option>
        <option value="page-actual">actual</option>
        <option value="page-fit">fit</option>
        <option value="page-width">width</option>
        <option value="0.50">50%</option>
        <option value="0.75">75%</option>
        <option value="1">100%</option>
        <option value="1.25">125%</option>
        <option value="1.50">150%</option>
        <option value="1.75">175%</option>
        <option value="2">200%</option>
        <option value="3">300%</option>
        <option value="4">400%</option>
      </select>
      <button @click="print">print</button>
    </template>
  </bsd-pdf>
</template>

<script>
export default {
  name: 'app',
  data() {
    return {
      src: 'https://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf',
      pageNum: null,
      scale: 1,
      currentNum: 1,
      pageLoaded: 0
    };
  },
  components: {},
  methods: {
    fileChanged() {
      this.file = this.src;
    },
    load(val) {
      this.pageNum = val;
    },
    setScale() {
      this.$refs.pdf.changeScale(this.scale);
    },
    scroll(val) {
      this.currentNum = val;
    },
    pagerender(val) {
      this.pageLoaded = val;
    },
    pre(){
      this.$refs.pdf.prePage();
    },
    next(){
      this.$refs.pdf.nextPage();
    },
    pageChange(val) {
      this.$refs.pdf.goToPage(val);
    },
    print() {
      this.$refs.pdf.printFile();
    }
  }
};
</script>

<style>
html,
body {
  width: 100%;
  height: 100%;
}
* {
  margin: 0;
  padding: 0;
}
#app {
  color: #2c3e50;
  width: 100%;
  height: 100%;
}
@media print {
  #app {
    display: none;
  }
}
</style>

Attributes

AttributeDescriptionTypeAccepted ValuesDefault
filePathpdf sourcestringβ€”β€”
widthpdf widthstring, numberβ€”100%
heightpdf heightstring, numberβ€”100%
atleastpdf heightstring, numberβ€”100%
useOnlyCssZoomonly use css zoombooleanβ€”false
showNavshow catalogue (
If the file does not have a directory, it does not work)booleanβ€”true
autoWidthWhether to scale PDF to container width during initializationbooleanβ€”false
textLayerModeRender in text mode, 0 use canvas,1 use text modenumber0/10

Events

Event NameDescriptionParameters
on-successsuccess eventcount page, pdf obj
on-pagerenderpagerender eventpage loaded
on-errorerror eventerror
on-scrollTriggered when scrolling pdfCurrent pages , Pdf Object

Methods

MethodDescriptionParameters
scalescaleScaling
prePagepre pageβ€”
nextPagenext pageβ€”
goToPagePDF change pagepage
printFilePrint all pdfscale

Slot

nameDescription
headerheader slot
footerfooter slot
loadingloading slot
0.0.1-security

2 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago