Giter Club home page Giter Club logo

vue-pdf-viewer's Introduction

📄 pdf-viewer-vue

PDF viewer component for Vue 2 and Vue 3

npm npm Github Repo stars npm

Compatibility

This package is compatible with both Vue 2 and Vue 3. The default exported build is for Vue 3, but dist directory also contains a build for Vue 2 (dist/vue2-pdf-viewer.js). See the example in Usage section.

Installation

Depending on the environment, the package can be installed in one of the following ways:

npm install pdf-viewer-vue
yarn add pdf-viewer-vue
<script src="https://unpkg.com/pdf-viewer-vue"></script>

Usage

<template>
  <div>
    <h1>File</h1>

    <PDFViewer
      :source="url"
      style="height: 100vh; width: 100vw"
      @download="handleDownload"
    />

    <h1>Base64</h1>

    <PDFViewer
      :source="base64"
      style="height: 100vh; width: 100vw"
      @download="handleDownload"
    />
  </div>
</template>

<script>
import PDFViewer from 'pdf-viewer-vue'

// OR THE FOLLOWING IMPORT FOR VUE 2
// import PDFViewer from 'pdf-viewer-vue/dist/vue2-pdf-viewer'

export default {
  components: {
    PDFViewer,
  },

  data() {
    return {
      url: '<PDF_URL>',
      base64: '<BASE64_ENCODED_PDF>',
    }
  },
}
</script>

Props

Name Type Accepted values Description
source string document URL or Base64 source of document
controls string[] [
'download',
'print',
'rotate',
'zoom',
'catalog',
'switchPage',
]
visible controls
loading-text string - loading text
rendering-text string - rendering text
settings { defaultZoom: number } - default settings
filename string null display filename

Events

Name Value Description
download {source: string; filename: string;} pdf file base info
loaded {total: number} document load completed
loading-failed Error failed to load document
rendered - finished rendering the document
rendering-failed Error failed to render document

Examples

TODO: CodeSandbox or JSFiddle

License

MIT License. Please see LICENSE file for more information.

vue-pdf-viewer's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vue-pdf-viewer's Issues

在form表单中预览点击头部按钮会刷新页面

如题,我有个需求是在form表单中进行预览,所以我毫不犹豫地将 PDFViewer 组件嵌套在 el-form 组件内,大概代码如下:

<el-form>
    <el-form-item>
        <PDFViewer />
    </el-form-item>
</el-form>

当我点击头部的缩放、下载、打印等按钮时,我的页面会刷新,因为 IconButton.vue 组件中的 button 未指定 type 属性,默认的 type 属性值是 submit,所以点击这些按钮会触发我表单的提交,从而导致刷新页面。

目前我的做法是阻止我表单提交,但是希望作者能够指定下 type="button" 以消除潜在的问题。

再次感谢作者写出这么好用的组件!!!

附上关于 type 的说明 :https://www.runoob.com/tags/att-button-type.html

edge兼容性问题 clientHeight

版本

"vue": "2.6.10",
"pdf-viewer-vue": "^0.2.6",

浏览器

edge: 版本 114.0.1823.67 (正式版本) (64 位)

报错信息

主要报错

[Vue warn]: Error in nextTick: "TypeError: Cannot read properties of undefined (reading 'clientHeight')"

完整报错

[Vue warn]: Error in nextTick: "TypeError: Cannot read properties of undefined (reading 'clientHeight')"

found in

---> <Viewer> at src/components/Viewer/Viewer.vue
       <PDFViewer> at src/PDFViewer.vue
         <PdfPreview> at src/views/multimode/components/pdfPreview.vue
           <App> at src/App.vue
             <Root>
warn @ vue.runtime.esm.js:619
logError @ vue.runtime.esm.js:1884
globalHandleError @ vue.runtime.esm.js:1879
handleError @ vue.runtime.esm.js:1839
eval @ vue.runtime.esm.js:1982
flushCallbacks @ vue.runtime.esm.js:1906
Promise.then(异步)
timerFunc @ vue.runtime.esm.js:1933
nextTick @ vue.runtime.esm.js:1990
Vue.$nextTick @ vue.runtime.esm.js:3515
mounted @ vue2-pdf-viewer.js:1
invokeWithErrorHandling @ vue.runtime.esm.js:1854
callHook @ vue.runtime.esm.js:4213
insert @ vue.runtime.esm.js:3139
invokeInsertHook @ vue.runtime.esm.js:6340
patch @ vue.runtime.esm.js:6559
Vue._update @ vue.runtime.esm.js:3942
updateComponent @ vue.runtime.esm.js:4060
get @ vue.runtime.esm.js:4473
run @ vue.runtime.esm.js:4548
flushSchedulerQueue @ vue.runtime.esm.js:4304
eval @ vue.runtime.esm.js:1980
flushCallbacks @ vue.runtime.esm.js:1906
Promise.then(异步)
timerFunc @ vue.runtime.esm.js:1933
nextTick @ vue.runtime.esm.js:1990
queueWatcher @ vue.runtime.esm.js:4396
update @ vue.runtime.esm.js:4538
notify @ vue.runtime.esm.js:730
reactiveSetter @ vue.runtime.esm.js:1055
proxySetter @ vue.runtime.esm.js:4625
eval @ pdfPreview.vue:88
eval @ vue.runtime.esm.js:1980
flushCallbacks @ vue.runtime.esm.js:1906
Promise.then(异步)
timerFunc @ vue.runtime.esm.js:1933
nextTick @ vue.runtime.esm.js:1990
Vue.$nextTick @ vue.runtime.esm.js:3515
mounted @ pdfPreview.vue:87
invokeWithErrorHandling @ vue.runtime.esm.js:1854
callHook @ vue.runtime.esm.js:4213
insert @ vue.runtime.esm.js:3139
invokeInsertHook @ vue.runtime.esm.js:6340
patch @ vue.runtime.esm.js:6559
Vue._update @ vue.runtime.esm.js:3942
updateComponent @ vue.runtime.esm.js:4060
get @ vue.runtime.esm.js:4473
run @ vue.runtime.esm.js:4548
flushSchedulerQueue @ vue.runtime.esm.js:4304
eval @ vue.runtime.esm.js:1980
flushCallbacks @ vue.runtime.esm.js:1906
Promise.then(异步)
timerFunc @ vue.runtime.esm.js:1933
nextTick @ vue.runtime.esm.js:1990
queueWatcher @ vue.runtime.esm.js:4396
update @ vue.runtime.esm.js:4538
notify @ vue.runtime.esm.js:730
reactiveSetter @ vue.runtime.esm.js:1055
eval @ vue-router.esm.js:2555
eval @ vue-router.esm.js:2554
updateRoute @ vue-router.esm.js:2013
eval @ vue-router.esm.js:1891
eval @ vue-router.esm.js:2000
step @ vue-router.esm.js:1730
step @ vue-router.esm.js:1737
runQueue @ vue-router.esm.js:1741
eval @ vue-router.esm.js:1995
step @ vue-router.esm.js:1730
eval @ vue-router.esm.js:1734
eval @ vue-router.esm.js:1980
eval @ vue-router.esm.js:1773
eval @ vue-router.esm.js:1849
Promise.then(异步)
eval @ vue-router.esm.js:1796
eval @ vue-router.esm.js:1817
eval @ vue-router.esm.js:1817
flatMapComponents @ vue-router.esm.js:1816
eval @ vue-router.esm.js:1752
iterator @ vue-router.esm.js:1959
step @ vue-router.esm.js:1733
step @ vue-router.esm.js:1737
eval @ vue-router.esm.js:1734
eval @ vue-router.esm.js:1980
_callee$ @ permission.js:31
tryCatch @ runtime.js:62
invoke @ runtime.js:296
prototype.<computed> @ runtime.js:114
asyncGeneratorStep @ asyncToGenerator.js:3
_next @ asyncToGenerator.js:25
eval @ asyncToGenerator.js:32
eval @ asyncToGenerator.js:21
eval @ permission.js:11
iterator @ vue-router.esm.js:1959
step @ vue-router.esm.js:1733
runQueue @ vue-router.esm.js:1741
confirmTransition @ vue-router.esm.js:1988
transitionTo @ vue-router.esm.js:1890
init @ vue-router.esm.js:2546
beforeCreate @ vue-router.esm.js:553
invokeWithErrorHandling @ vue.runtime.esm.js:1854
callHook @ vue.runtime.esm.js:4213
Vue._init @ vue.runtime.esm.js:4998
Vue @ vue.runtime.esm.js:5079
eval @ main.js:34
./src/main.js @ app.js:6196
__webpack_require__ @ app.js:849
fn @ app.js:151
1 @ app.js:9098
__webpack_require__ @ app.js:849
checkDeferredModules @ app.js:46
(匿名) @ app.js:925
(匿名) @ app.js:928
vue.runtime.esm.js:1888  TypeError: Cannot read properties of undefined (reading 'clientHeight')
    at eval (vue2-pdf-viewer.js:1:1)
    at VueComponent.eval [as handleResize] (vue2-pdf-viewer.js:1:1)
    at VueComponent.eval (vue2-pdf-viewer.js:1:1)
    at Array.eval (vue.runtime.esm.js:1980:1)
    at flushCallbacks (vue.runtime.esm.js:1906:1)

Add option to enable download of pdfs using redirected source

Hello,

Currently, I'm utilizing vue-pdf-viewer to download PDFs, and the links provided make requests to my API, which subsequently redirects to an AWS S3 location. The challenge I'm facing is related to visualizing PDFs that originate from redirected requests (status 302). The visualizer opens but the pdf has an empty content.

All authorizations are correct and for the direct link the PdfViewer works correctly.

I did not find anything related in the docs but does the lib per default , blocks content from redirected requests?

Publish release on NPM

Currently last release on NPM is 0.2.7. It would be nice if we could have the latest.

文件名可以当作props来指定吗?

现在的文件名是通过URL来自动获取的,但往往好多时候URL自带的文件名并不是真正pdf的名字,所以希望可以有一个指定文件名的功能

分页加载

在移动端浏览器中 一次性加载缓慢 希望提供对pdf分页加载的方法 先加载前几页 屏幕滚动快滚动到底部继续加载后几页
vue3.0

0.2.8版本build报错了

错误描述如下:
error in ./node_modules/pdf-viewer-vue/dist/vue2-pdf-viewer.js

Module parse failed: Unexpected token (1:1812561)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

setting zoom not working

I just wanna set the default zoom of page and write the element like this

<PDFViewer :source="url" class="w-full h-full" @Download="handleDownload(url)" :settings="{ defaultZoom:175 }" />

but noting happend

能否支持工具栏扩展按钮以及自定义重写现有的按钮方法?

您好,有时间需要在打印之前做点什么,希望可以修改打印按钮的行为,或者增加自定义按钮做某些事情?
但是我clone源码之后没跑起来,两个疑问:环境要求node版本是多少?能用pnpm代替yarn吗?
PS: 我目前用的 node: 14.15.0

感谢大佬的贡献!

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.