我需要缩放pdf,使其填充屏幕的高度,但我找到的只是函数
scale()
。我怎么知道要缩放多少?
要确定页面的宽度/高度,您需要执行以下操作:
获取页面
在“promise”函数中(只能异步检索页面):
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 );
});
从 getViewport 获取 pdf 宽度和高度(以英寸为单位)
let viewport= page.getViewport({ scale: 1 });
let inchHeight=viewport.height/72;
let inchWidth=viewport.width/72;
转换为像素
let pixleHeight=inchHeight*96;
let pixleWidth=inchWidth*96;
从 Adobe 中查找文档页面尺寸(英寸) -> 在 Adobe 中打开文档,转到文件 -> 属性或 ctrl+d