簡體   English   中英

如何使用pdf.js確定pdf的大小,以便我可以縮放到屏幕大小?

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

我需要縮放一個pdf,以便它填滿屏幕的高度,但我發現的只是函數scale() 我怎么知道要縮放多少?

要確定頁面的寬度/高度,您需要執行以下操作:

  1. 獲取頁面

  2. 在“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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM