typescript - How to download a pdf using fileSaver and Angular 2 -
i stored pdf file inside angular 2 project. want download file onclick of button. here html code-
<a class="btn-u btn-u-sm" (click)="savedemo()">download <i class="fa fa-angle-double-right margin-left-5"></i></a>
and component.ts
import { component } '@angular/core'; import { registrationcomponent } '../registration/app.registration'; import { saveas } 'file-saver'; @component({ templateurl: './app.pronto.html' }) export class prontocomponent { savedemo() { let file = new blob(['../../../files/skybase.pdf'], { type: 'application/pdf;charset=utf-8' }); saveas(file, 'skybase.pdf') } }
but blank pdf downloading. should do?
if file on same directory of project
why using coding , can directly use download
attribute of a
tag
<a href="path_to_pdf" download>
note : if path correct , file downloaded otherwise blank , same issue in code. check file path , make sure correct.
<a href="path_to_pdf" download="new_filename">
specifies new filename downloaded file
<a href="https://www.w3schools.com/images/myw3schoolsimage.jpg" download="w3logo">w3 logo</a>
Comments
Post a Comment