【问题标题】:ng2-pdfjs-viewer Pass Object from component to htmlng2-pdfjs-viewer 将对象从组件传递到 html
【发布时间】:2020-05-06 18:12:13
【问题描述】:

我正在使用 ng2-pdfjs-viewer,我可以传递一个 pdf 文件 http url,但我不能使用插值,也不能将变量传递给 html 标记内的 pdfSrc 选项,以从休息服务响应中呈现 pdf。

如何将 Uint8array 或 base64 对象从 component.ts 传递到 component.html?

【问题讨论】:

    标签: angular pdf angular7 pdf.js ng2-pdfjs-viewer


    【解决方案1】:

    此处提供了您的案例示例:https://ng2-pdfjs-viewer.azurewebsites.net/bytearray

    代码提取

    your.component.html

    <div style="height: 600px">
        <ng2-pdfjs-viewer #pdfViewer></ng2-pdfjs-viewer>
    </div>
    

    your.component.ts

     @ViewChild('pdfViewer') public pdfViewer;
    
    constructor(private http: HttpClient) {
        let url = "api/document/getmypdf";
        this.downloadFile(url).subscribe(
            (res) => {
                this.pdfViewer.pdfSrc = res; // pdfSrc can be Blob or Uint8Array
                this.pdfViewer.refresh(); // Ask pdf viewer to load/refresh pdf
            }
        );
    }
    
    private downloadFile(url: string): any {
        return this.http.get(url, { responseType: 'blob' })
            .pipe(
                map((result: any) => {
                    return result;
                })
            );
    }
    

    【讨论】:

    • 您能澄清一下通过结果映射器将可观察对象传递给自身的原因吗?非常感谢。
    • @VBobCat 可能在那里做了什么。忽略它。
    猜你喜欢
    • 2021-01-01
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    • 2020-01-27
    • 2020-04-24
    • 2020-08-08
    • 2019-11-12
    • 1970-01-01
    相关资源
    最近更新 更多