Giter VIP home page Giter VIP logo

vue-pdf.js-demo's Introduction

pdfjs-vueDemo

A Vue.js project

Build Setup

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build

# build for production and view the bundle analyzer report
npm run build --report

页面

官方demo:http://mozilla.github.io/pdf.js/web/viewer.html

  1. 预览本地pdf
    将viewer.js 的 10053 放开,10054注释,输入路径 http://localhost:8080/static/pdf/web/viewer.html 或者 访问 http://localhost:8080/static/pdf/web/viewer.html?file=/static/pdf/web/demo.pdf
  2. 预览服务器的pdf
    2.1 let url = 'http://somedomain/doc/manuals/R-intro.pdf'
    2.2 let url = 'http://image.cache.timepack.cn/nodejs.pdf'
    这两个url 都是我网上自己找的,虽然都是服务器pdf路径,通过(http://localhost:8080/static/pdf/web/viewer.html?file=http://image.cache.timepack.cn/nodejs.pdf)访问但是上面第一个会报错,第二个可以正常预览是因为第一个的服务器端没有设置Access-Control-Allow-Origin:*,允许跨域,so R-intro.pdf的预览就会报 '意外的服务器相应,Unexpected server response (0) while retrieving PDF "http://somedomain/doc/manuals/R-intro.pdf". 猜测会有人报'file origin does not match viewer.js' 我没报的原因是我简单粗暴的将viewer.js的1863行注释了! 但是配置服务器允许跨域不安全也不好,so,这就需要后台来配合了,后台需要返回你一个流的形式的pdf,pdf.js插件是可以识别的,也不会报跨域问题!!!
    2.3 let url = 'https://dluat.hscf.com/api/esm/v1/contractTemplates/load/c08def54aa40412b8b511406fc0271d2/0?access_token=b6cce0c8428c55531d206b4f008fe44e&name=cehsi.pdf' 将上面的url放入浏览器直接 是以流的形式呈现出来,例如下面的乱码形式:

%PDF-1.4
5 0 obj
<< /Type /Page
/Parent 3 0 R
/Resources 4 0 R
/Contents 6 0 R
/MediaBox[ 0 0 595.3 841.9 ]
/CropBox[ 0 0 595.3 841.9 ]
/Rotate 0

endobj
6 0 obj
<< /Length 273 /Filter /FlateDecode >>
.......还有很多这种码
这种带有参数的url必须编码,encodeURIComponent了解一下,当然以流的方式在浏览器打开是进行下载的,pdf.js也是可以进行预览,而不下载。
// 启动项目
npm install or cnpm install
npm run dev
For a detailed explanation on how things work, check out the guide and docs for vue-loader.

vue-pdf.js-demo's People

Contributors

gosunadeod avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

vue-pdf.js-demo's Issues

打印时多一个空白页

您好,在项目中使用这个方法时,点击预览页面的打印按钮,此时会比预览时多一个空白页,请问这个问题的原因是什么?怎么解决?谢谢

浏览器打开空白页

允许作者项目案例没有问题,将下列案例放入自己的项目中,
checkNormal() {
let url = 'http://image.cache.timepack.cn/nodejs.pdf' // 有效 服务器配置跨域处理
window.open('/static/pdf/web/viewer.html?file=' + url)
},
打开的新窗口出现空白页,同时控制台出现Uncaught SyntaxError: Unexpected token < 问题

后台返回流的形式指的是什么

请问一下,这儿指的后台返回流的形式,指的是将文件的url通过流的形式返回,但是pdf还是原来的pdf,然后通过请求获取到,再进行处理;还是指的是将整个pdf都必须是流的形式,然后再通过url进行进行访问

启动项目不成功

想把您的这个代码合到我的项目里,可是拷贝后每次building到static/pdf/build/pdf.js就卡死了
WX20191021-171929@2x
怎么都过不去,请问是什么原因呢?(PS:我的依赖还没装,想着等编译后根据错误提示来安装依赖~)

pdf表单域

请问pdf表单域在转换时,部分显示,部分不能显示。请问怎么解决?

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.