• pdf.js


    下载pdf.js

    下载

    https://gitee.com/lovers_der/pdf.js.git
    
    <style>
        .contract-modal {
            position: absolute;
            right: 15%;
             1000px;
            overflow: scroll;
            background: rgba(139, 148, 171, 0.7);
            padding: 20px 0 0;
            z-index: 900;
        }
        .contract-modal .contract-detail {
            margin: 0 auto;
            max- 96%;
            height: auto;
        }
    
        #mycanvas {
            min-height: 50vh;
            background: #fff;
        }
        canvas{
            margin: 0 auto;
            display: block;
            border-bottom:2px solid #aaa;
        }
    </style>
    
    <template>
        <div class="contract-modal">
            <div class="contract-detail"
                    id="contractDetail">
                <div id="mycanvas" ref="mycanvas"></div>
            </div>
        </div>
    </template>
    
    <script>
        import pdf from '../../static/pdf/build/pdf'
        export default {
            name: 'md-contract',
            data () {
                return {}
            },
            methods: {
                getPage (pdf,pageNumber,container,numPages) { //获取pdf
                    let _this = this
                    pdf.getPage(pageNumber).then((page) => {
                        let scale = (container.offsetWidth/page.view[2])
                        let viewport = page.getViewport(scale)
                        let canvas = document.createElement("canvas")
                        canvas.width= viewport.width
                        canvas.height= viewport.height
                        container.appendChild(canvas)
                        let ctx = canvas.getContext('2d');
                        var renderContext = {
                            canvasContext: ctx,
                            transform: [1, 0, 0, 1, 0, 0],
                            viewport: viewport,
                            intent: 'print'
                        };
                        page.render(renderContext).then(() => {
                            pageNumber +=1
                            if(pageNumber<=numPages) {
                                _this.getPage(pdf,pageNumber,container,numPages)
                            }
                        })
                    })
                },
                getPdf () {
                    // 此中方式接受流形式返回
                    let url = '/static/english.pdf'//pdf地址
                    let pdfjsLib = pdf
                    pdfjsLib.PDFJS.workerSrc = '/static/pdf/build/pdf.worker.js'
                    let loadingTask = pdfjsLib.getDocument(url)
                    loadingTask.promise.then((pdf) =>{
                        let numPages = pdf.numPages
                        let container = document.getElementById('mycanvas')
                        let pageNumber = 1
                        this.getPage(pdf,pageNumber,container,numPages)
                    }, function (reason) {
                        alert(reason)
                    });
                }
            },
            created () {
                //初始化
                this.getPdf()
            }
        }
    </script>
    
  • 相关阅读:
    四个例子实战讲解.htaccess文件rewrite规则(转)
    unserialize反序列化错误的解决办法
    tp框架--------where("1")
    jq 鼠标点击跳转页面后 改变点击菜单的样式代码
    jq不懂的地方
    js产生随机数的几个方法
    js邮箱,汉字,数字 表单验证
    js&jQ判断checkbox表单是否被选中
    绝对好用Flash多文件大文件上传控件
    CKeditor从Word粘贴格式问题
  • 原文地址:https://www.cnblogs.com/corvus/p/14961108.html
Copyright © 2020-2023  润新知