Pdf.js and viewer.js. Pass a stream or blob to the viewer

前端 未结 5 1612
一个人的身影
一个人的身影 2020-11-27 15:40

I\'m having troubles in finding a solution for this: I retrieve a PDF blob from a SQL filestream field using Javascript in this way (it\'s a lightswitch project)

<         


        
5条回答
  •  天命终不由人
    2020-11-27 16:39

    I am using viewer in an iframe;

     
    

    And fetch API used as follows;

     fetch(pdfSourceUrl).then((response: Response) => {
                response.blob().then((blob) => {
                  var url = URL.createObjectURL(blob);
                  pdfIframe.src = `pdfjs/web/viewer.html?file=${url}`;
                });
              });
    

    Eventually iframe src created as follows;

    http://localhost:9000/pdfjs/web/viewer.html?file=blob:http://localhost:9000/14f6a2ec-ad25-40ab-9db8-560c15e90f6e

提交回复
热议问题