[英]How do I determine the size of a pdf with pdf.js so I can scale to the screen size?
我需要縮放一個pdf,以便它填滿屏幕的高度,但我發現的只是函數scale()
。 我怎么知道要縮放多少?
要確定頁面的寬度/高度,您需要執行以下操作:
獲取頁面
在“promise”函數中(頁面只能異步檢索):
一個。 以1
為單位檢索視口
灣 調用視口的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 );
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.