iPad上的PDFJ模糊PDF



我正在Cordova应用程序中的PDJS视图。

除了pdf有点模糊之外,一切都很好。我知道这是某种程度上是因为视网膜显示的,但是我该如何更改此ODER如何获得正确的尺度?

目前我尝试这个

pdfFile.getPage(data.page).then(function (page) {

    canvas.width = $('#pdfContainer').width();
    var viewport = page.getViewport(canvas.width / (page.getViewport(1).width));
    canvas.width = viewport.width;
    canvas.height = viewport.height;
    var height= $('#pdfContainer').height();

    if (canvas.height > height) {
        canvas.height = height;
        var viewport = page.getViewport(canvas.height / (page.getViewport(1).height));
        canvas.width = viewport.width;
        canvas.height = viewport.height;
    }
    var renderContext = {
        canvasContext: context,
        viewport: viewport
    };
    page.render(renderContext);
});

我为此所做的是首先停用图像平滑:

canvasContext = canvas.getContext('2d') as CanvasRenderingContext2D;
canvasContext.imageSmoothingEnabled = false;
canvasContext.webkitImageSmoothingEnabled = false;
canvasContext.mozImageSmoothingEnabled = false;
canvasContext.oImageSmoothingEnabled = false;

然后使用window.devicePixelRatio

乘以devicePixelRatio
    if (window.devicePixelRatio > 1) {
        var canvasWidth = canvas.width;
        var canvasHeight = canvas.height;
        canvas.width = canvasWidth * window.devicePixelRatio;
        canvas.height = canvasHeight * window.devicePixelRatio;
        canvas.style.width = canvasWidth + "px";
        canvas.style.height = canvasHeight + "px";
        canvasContext.scale(window.devicePixelRatio, window.devicePixelRatio);
    }

这也修复了带有视网膜显示器的Macbocks的模糊效果。

最新更新