【问题标题】:Add element <button> on ng2-pdf-viewer Angular在 ng2-pdf-viewer Angular 上添加元素 <button>
【发布时间】:2020-01-18 13:39:33
【问题描述】:

我需要使用ng2-pdf-viewer 在我的组件上显示PDF file,但其中一项要求是,我需要添加button download,并且它必须与PDF file 重叠,尝试查找有关此的任何参考,但没有找到,这是我尝试过的,

component.html

        <button (click)="toggle()">VIEW RECEIPT</button>
        <div style="height:715px">
            <pdf-viewer *ngIf="isHideReceipt" [autoresize]="true" [src]="pdfSrc" [original-size]="false"
                [render-text]='false' [show-all]="false" style="display: block;position: relative"
                [fit-to-page]="true">
            </pdf-viewer>
            <button (click)="download()">Download PDF</button>
        </div>

component.ts

  pdfSrc = '../../assets/pdf/bla3.pdf';

  toggle() {
    this.isHideReceipt = !this.isHideReceipt;
  }

  download() {
    const blob = this.pdfSrc;
    saveAs(blob, 'test1.pdf');
  }

根据要求(按钮下载重叠的 pdf),我尝试使用 z-index 之类的 CSS,但没有用,有可能吗?

链接到official ng2-pdf-viewer

【问题讨论】:

  • it doesn't work 是什么意思?是不是没有出现,是不是出现在了错误的地方?如果有的话,请发布您的其余 css 代码。
  • 按钮下载不显示,不重叠pdf file

标签: html css angular typescript pdf


【解决方案1】:

将按钮元素设置为具有绝对位置,并将其父容器设置为具有相对位置。这样你就可以重叠到 pdf 查看器上:

        <button (click)="toggle()">VIEW RECEIPT</button>
        <div style="position: relative; height:715px;">
            <pdf-viewer *ngIf="isHideReceipt" [autoresize]="true" [src]="pdfSrc" [original-size]="false"
                [render-text]='false' [show-all]="false" style="display: block;position: relative"
                [fit-to-page]="true">
            </pdf-viewer>
            <button style="position: absolute; right: 10px; bottom: 10px;" (click)="download()">Download PDF</button>
        </div>

【讨论】:

  • 嗨伙计,它的工作,我只需要了解更多关于css的知识,位置绝对和相对,如果可以,你能解释更多答案吗,
  • position: relative 设置为父级意味着它相对于自身定位并且不设置底部/顶部或左/右属性意味着它根本不会改变它的位置(我知道有点令人困惑)但是将其设置为相对的全部目的是您可以将按钮的位置设置为绝对的,因此它将相对于父容器(如果父容器没有相对定位,那么按钮将在其中真正是绝对的如果css属性是默认的,则很可能位于文档的底部)
  • css-tricks.com/… 解释得比我能解释的要好得多;)
猜你喜欢
  • 2022-07-26
  • 1970-01-01
  • 2021-12-27
  • 2018-03-26
  • 2019-06-03
  • 2018-03-06
  • 1970-01-01
  • 2022-11-28
  • 1970-01-01
相关资源
最近更新 更多