首页 > 解决方案 > 如何在 Angular 11 中隐藏 ng2-pdfjs-viewer 中的工具栏?

问题描述

如何在 ng2-pdfjs-viewer 中隐藏整个工具?我用它来显示pdf

提前致谢

在我的 html 中,我有这个:-

<ng2-pdfjs-viewer #embeddedPdf id="pdfViewer" aria-label="Embedded PDF" [pdfSrc]="pdfBlob" zoom="page-width" [download]="false" [find]="false"
                      [print]="false" [startPrint]="false" [startDownload]="false" [rotatecw]="false" [rotateccw]="false" [fullScreen]="false"
                      [openFile]="false" [viewBookmark]="false" [showSpinner]="true" [errorAppend]="false"></ng2-pdfjs-viewer>

在我的 Ts 文件中,我有这个:-

export class PdfComponent implements AfterViewChecked{

  @Input() pdfBlob: Blob;

  @ViewChild('embeddedPdf') embeddedPdf: PdfJsViewerComponent;


  constructor(private sanitizer: DomSanitizer) {
  }

  ngAfterViewChecked() {

   console.log("Toolbar  = "+this.embeddedPdf);
    if(this.embeddedPdf && this.embeddedPdf.PDFViewerApplication){
      this.embeddedPdf.PDFViewerApplication.toolbar.toolbar.hidden=true;
      console.log(this.embeddedPdf.PDFViewerApplication);
    }
  
  }
}

使用它我实际上可以隐藏组件:-

this.embeddedPdf.PDFViewerApplication.toolbar.toolbar.hidden=true;

但 PDFViewerApplication 仅在页面完全加载后可用。因此,在这种方法 ngAfterViewChecked 中,我无法在页面初始化时隐藏工具栏。

标签: angular11pdf-viewer

解决方案


推荐阅读