2016-06-16 58 views
1

我正在一個cordova APP中的PDJS視圖上工作。PDFJs在iPAD上的模糊PDF

一切工作正常,但PDF是有點模糊。我知道這是由於視網膜顯示,但我怎樣才能改變這個奧得我如何得到正確的尺度?

目前我試試這個

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); 
}); 
+0

你有沒有設法弄清楚這一點?我有完全一樣的問題。 – distante

+0

是的,仍然需要幫助嗎? –

+0

@distante急?否則,我將在稍後提供答案 –

回答

1

什麼我做了,這是第一次全部停用圖像平滑:

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

然後乘以devicePixelRatio,我覺得用window.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); 
    } 

這也修復了視網膜麥克風的模糊效果d isplays。