Include a <button> element in the Angular ng2-pdf-viewer framework

I am looking to showcase a PDF file on my component using ng2-pdf-viewer. One of the requirements is to include a download button that overlaps the PDF file. I have searched for references on how to achieve this but unfortunately, I haven't found any solution. Here is what I have attempted so far:

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');
  }

For the specific requirement of having the download button overlap the pdf, I have attempted to use CSS properties like z-index without success. Is there a way to achieve this?

Link to official ng2-pdf-viewer https://i.sstatic.net/ZddjC.jpg

Answer №1

To ensure the button element overlaps onto the pdf viewer, set its position to absolute and its parent container's position to relative:

        <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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The AOT Compilation error occurs in Angular2 RC6 when trying to call the function RouterModule.forChild(ROUTES) which is not supported

Operating Environment: Windows 10, IntelliJ 2016.2, node Angular Version: 2.0.0-rc.6 Language: [all | TypeScript X.X | ES6/7 | ES5] Typescript ES6 Node (for Ahead of Time Compilation issues): node --version = Node 4.4.7, NPM 3.10.6 The AOT com ...

Setting up aliases for "HTML import" paths - a step-by-step guide

Recently, I've been experimenting with Web Components and Polymer, creating a basic single-page application. Within my project, I have various custom components. My HTML imports are structured like this: <link rel="import" href="../core-icon/core ...

Launch a modal window that displays a form generated using ngx-formly, which is nested within another form also created with

I have been utilizing ngx-formly to generate Angular forms dynamically from JSON data, and it has been working smoothly. One interesting scenario I encountered involves a custom button on a form that needs to open a modal dialog containing another form upo ...

Different Options to Explore Instead of Using @apollo/federation Library

We are currently developing typescript microservices with REST APIs and are exploring the possibility of integrating GraphQL into each microservice, along with implementing an API Gateway at the top level to combine everything into a single API. Although ...

Troubleshooting: Issues with jQuery animate() not functioning properly when adjusting CSS

Currently, I am experimenting with jQuery's .animate() function to change the background of a div when it is scrolled more than 100 pixels down a page. Previously, I had successfully used .css() for this purpose. JS: $(window).scroll(function () { ...

What is the best way to call a JavaScript function with multiple arguments from a Silverlight project?

I encountered an issue when trying to invoke a JavaScript function with multiple arguments from an HTML page. Here is what I am attempting to do: wbNavigator.Navigate(new Uri("http://localhost:56433/route.html", UriKind.Absolute)); object results = wbNavi ...

The initial item on the list, displayed on the right side in Google Chrome

Currently experiencing an issue with Google Chrome where the first list item's bullet is floating right while all other list items' bullets are aligned correctly at left. Here is the code snippet causing the problem: <div class="window_sub_ ...

The previous method of using `vue/compiler-sfc ::v-deep` as a combinator has been phased out. Instead, opt for the new syntax `:deep(<

When developing with Nuxt 2, I am encountering numerous [@vue/compiler-sfc] ::v-deep usage as a combinator has been deprecated. Use :deep(<inner-selector>) instead. errors when running npm run dev. After attempting to resolve the issue by changing a ...

The div height set to 100% and using display:flex is experiencing issues in Chrome

Bootstrap 3.0 is utilized in the design. My goal is to have uniform height for all boxes, with the "more" link on the right box positioned correctly. However, the box ends before reaching the more link. Take a look at this JSFiddle example. Here is the H ...

Learn how to dynamically alter the background color of a webpage by utilizing a JSON API for random color selection

My goal is to trigger a javascript function onload that will dynamically change the background color of the webpage using random colors fetched from a JSON file. ...

Why is the oninput function in JavaScript not functioning properly?

After following a practical video tutorial step by step, I tried to implement the code provided (in HTML and JS) but nothing seems to be working! The code snippet from the tutorial includes: var $count = document.getElementById("count"), $textarea = ...

The Proper Way to Include External CSS in a Next.js Page Without Triggering Any Warnings

I find myself in a scenario where I must dynamically inject CSS into a webpage. The content of this page is constantly changing, and I am provided with raw HTML and a link to a CSS file from a server that needs to be displayed on the page. My attempt to ...

Upgrade from Angular 4 to Angular 5 via the Visual Studio template is causing some challenges

I am in the process of upgrading my Angular project from version 4 to version 5, which is included in the template provided by Visual Studio 2017 (File -> New -> Project -> ASP.NET Core Web Application -> Angular). However, all the angular pac ...

Transform the IO type to an array of Either in functional programming with the fp-ts

Looking for assistance with implementing this in fp-ts. Can someone provide guidance? const $ = cheerio.load('some text'); const tests = $('table tr').get() .map(row => $(row).find('a')) .map(link => link.attr(&apos ...

Employing Typescript types in array notation for objects

Can someone please help me decipher this code snippet I found in a file? I'm completely lost as to what it is trying to accomplish. const user = rowData as NonNullable<ApiResult["getUsers"]["data"][number]["users"]> ...

How can TypeScript be forced to output a specific data type?

I've created a generic "fetcher" function that is designed to handle different types of entities. However, I'm encountering an issue where TypeScript is inferring the return type based on all possible conditions within the function. Is there a w ...

Angular 2: Emptying input field value on click event

I am experiencing an issue with resetting my input values. I have a search bar with filter functions. When I enter a value, it displays a list below and I want to add a function to these links. When I click on one of them, it takes me to another component ...

What is the best way to hand off a component to a helper function?

I am trying to create a helper function in TypeScript that takes a component as an argument and returns an array of objects, each containing a component node... // helpers.ts import { LINKS } from '../constants'; // error on the next line: Cannot ...

Is Joomla equipped with shortcodes akin to those found in Wordpress?

One of the great features of WordPress is the ability to use shortcodes to insert information into HTML without the need for programming knowledge in PHP or JavaScript. This simplifies tasks and increases safety. For example (this is just a hypothetical s ...

How can I stop the SvelteKit production node server from filling up the logs with "Error: not found /path/here"?

After developing a website using sveltekit, I decided to build it for production as a nodejs server and deploy it on my linux server with Caddy as a reverse proxy. Unexpectedly, upon starting the server, I began receiving error messages in the log such as ...