How do I determine the size of a pdf with pdf.js so I can scale to the screen size?

≡放荡痞女 提交于 2019-12-06 02:36:59

问题


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?


回答1:


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

  1. Get the page

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

    a. Retrieve the viewport with a scale of 1

    b. Call the width property of the viewport

The Code:

//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 );
});


来源:https://stackoverflow.com/questions/19042950/how-do-i-determine-the-size-of-a-pdf-with-pdf-js-so-i-can-scale-to-the-screen-si

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!