2013-09-27 94 views
4

我需要擴展一個pdf,所以它填充屏幕的高度,但我發現的是功能scale()。我如何知道要衡量它有多大?如何用pdf.js確定pdf的大小,以便可以縮放到屏幕大小?

+0

你指的是單個頁面或完整的PDF文件? –

+0

@Mr_Green我沒有想過每個頁面的大小可能不同。我想縮放每個頁面(當用戶去那個頁面)成爲屏幕的高度。 –

+0

@Mr_Green我解決了它。你可以在下面看到我的答案。 –

回答

4

確定網頁的寬度/高度,你需要做到以下幾點:

  1. 獲取頁面

  2. 在「承諾」功能(該頁面只能異步檢索):

    a。檢索比例爲1

    b。調用視

的代碼width屬性:

//Get the page with your callback 
pdf.getPage(1).then(function(page) { 

    //We need to pass it a scale for "getViewport" to work 
    var scale = 1; 

    //Grab the viewport with original scale 
    var viewport = page.getViewport(1); 

    //Here's the width and height 
    console.log("Width: " + viewport.width + ", Height: " + viewport.height); 
}); 
相關問題