Don*_*mmy 5 javascript pdf html5 pdf.js
我需要缩放一个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 );
});
Run Code Online (Sandbox Code Playgroud)