4
我需要擴展一個pdf,所以它填充屏幕的高度,但我發現的是功能scale()
。我如何知道要衡量它有多大?如何用pdf.js確定pdf的大小,以便可以縮放到屏幕大小?
我需要擴展一個pdf,所以它填充屏幕的高度,但我發現的是功能scale()
。我如何知道要衡量它有多大?如何用pdf.js確定pdf的大小,以便可以縮放到屏幕大小?
確定網頁的寬度/高度,你需要做到以下幾點:
獲取頁面
在「承諾」功能(該頁面只能異步檢索):
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);
});
你指的是單個頁面或完整的PDF文件? –
@Mr_Green我沒有想過每個頁面的大小可能不同。我想縮放每個頁面(當用戶去那個頁面)成爲屏幕的高度。 –
@Mr_Green我解決了它。你可以在下面看到我的答案。 –