网站搜索

angular - Syncfusion PdfViewer - 直接从 Blob 加载数据


我的问题是如何直接从 Blob 加载 PDF。我不想调用 API 获取响应。问题是下面的代码会对 /load 调用 API。为什么会这样,我该如何避免?

Typescript :

  public service = 'http://localhost:4200/api/';
  public load() {
    this.gdvService.getData(this.data.id, this.data.configuration)
    .subscribe(gdvData => {
      const responseData = gdvData[this.data.configuration.dataColumn];
      const blob = new Blob([responseData], { type: 'application/pdf' });
      const reader = new FileReader();
      reader.readAsBinaryString(blob);
      reader.onloadend = () => {
        const base64data = reader.result;
        const pdfviewer = (document.getElementById('pdfViewer') as any).ej2_instances[0];
        pdfviewer.load(base64data, null);
      };
    });
  }

HTML :

<ejs-pdfviewer id="pdfViewer" [serviceUrl]='service' style="height:640px;display:block"></ejs-pdfviewer>

答案#1

Syncfusion PDF 查看器控件既面向服务器端也面向客户端。PDF 查看器控件在服务器端(使用 .NET 环境开发)处理 PDF 文档,并通过 Web 服务将处理后的 PDF 数据发送到客户端,以渲染 PDF 文档并在 PDF 查看器中进行进一步操作。因此,目前无法在没有服务器端的情况下在 PDF 查看器中加载 PDF 文档。

此致, Akshaya