如何使用pdf.js确定pdf的大小,以便我可以缩放到屏幕大小? [英] How do I determine the size of a pdf with pdf.js so I can scale to the screen size?

查看:1771
本文介绍了如何使用pdf.js确定pdf的大小,以便我可以缩放到屏幕大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要缩放一个pdf,以便它填满屏幕的高度,但我找到的只是函数 scale()。我怎么知道要缩放多少?

I need to scale a pdf so it fills the height of the screen, but all I've found is the function scale(). How do i know how much to scale it?

推荐答案

要确定页面的宽度/高度,你需要这样做以下:

To determine the width/height of a page, you need to do the following:


  1. 获取页面

  1. Get the page

promise功能(页面只能异步检索):

In a "promise" function (the page can only be retrieved asynchronously):

a。检索视口的比例为 1

a. Retrieve the viewport with a scale of 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.js确定pdf的大小,以便我可以缩放到屏幕大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆