动态加载pdf模糊pdfjs

时间:2019-04-18 04:17:47

标签: pdf loading pdfjs blurry

动态加载pdf模糊文件,同一文件的官方演示非常清楚。我找不到问题了吗?

使用Chrome浏览器。版本73.0.3683.86(正式版本)(64位)
这是我的代码:

async loadingPdf(getUint8Array, index) {
        //渲染canvas
                let pdf = await pdfjsLib.getDocument({ data: getUint8Array, cMapUrl: cMapUrl, cMapPacked: cMapPacked  });
                let page = await pdf.getPage(1).then(page => {
                    return page;
                });
                let canvas = document.getElementById("the-canvas" + index);
                var viewport = page.getViewport(1.7);
                if (canvas.dataset.runed) return;
                //var CSS_UNITS = 150.0/ 72.0;
                var CSS_UNITS =120.0/ 72.0;
                canvas.width = viewport.width*CSS_UNITS;
                canvas.height = viewport.height*CSS_UNITS;
                //  canvas.width = viewport.width;
                //   canvas.height = viewport.height;
                this.canvasW =
                this.canvasW > (1000 / viewport.height) * viewport.width
                ? this.canvasW
                : (1000 / viewport.height) * viewport.width;
                canvas.style.width = (1000 / viewport.height) * viewport.width;
                canvas.dataset.runed = true;
                var context = canvas.getContext('2d');
                // 【重要】关闭抗锯齿
                context.mozImageSmoothingEnabled = false;
                context.webkitImageSmoothingEnabled = false;
                context.msImageSmoothingEnabled = false;
                context.imageSmoothingEnabled = false;
                await page.render({
                    //enableWebGL: true,
                    // canvasContext: context,
                    transform: [CSS_UNITS, 0, 0, CSS_UNITS, 0, 0],
                    //  transform: [1, 0, 0, 1, 0, 0],
                canvasContext: canvas.getContext("2d"),
                    viewport: viewport
                });
                this.loadedPages.push(index)
        },

我无法准确查明问题,并且显然看不到所有源代码。

0 个答案:

没有答案