【问题标题】:How to display pdf on canvas using angular7 and fabric js如何使用angular7和fabric js在画布上显示pdf
【发布时间】:2019-10-15 20:02:16
【问题描述】:

我想使用 angular7 和 fabric js 在画布上显示 pdf 作为图像

我在 angular7 中找不到任何可以尝试的代码

【问题讨论】:

    标签: angular7


    【解决方案1】:

    终于我能够解决这个问题了...我使用了 pdfjsLib 并且我已经导入了我的 ts 文件(import * as pdfjsLib from 'pdfjs-dist/build/pdf';)

     public src="/assets/myPhotos.pdf";
     showPdf(){
    pdfjsLib.getDocument(this.src).then(doc =>{
    
     // console.log("this file has "+ doc._pdfInfo.numPages+ "pages");
      doc.getPage(1).then(page => {
        var myCanvas =  <HTMLCanvasElement>document.getElementById("my_canvas");
        var context = myCanvas.getContext("2d");
        var scale = 1.5;
        var viewport = page.getViewport(scale);
        myCanvas.width = viewport.width;
        myCanvas.height = viewport.height;
    
        page.render({
          canvasContext : context,
          viewport : viewport
        })
      })
    });
    

    }

    【讨论】:

      猜你喜欢
      • 2023-04-02
      • 2018-03-20
      • 2021-09-15
      • 2017-11-23
      • 1970-01-01
      • 2020-01-19
      • 2020-01-13
      • 1970-01-01
      • 2017-08-16
      相关资源
      最近更新 更多