showpdf in angular html

30 views
Skip to first unread message

sandeep...@gmail.com

unread,
Jun 25, 2020, 5:37:15 PM6/25/20
to Angular and AngularJS discussion
Hi,

I would like to show the PDF in my html. I am getting the pdf file in base64 format and it is part of attribute in json. eg  in my ts file I am saving in one variable say 
       pdf = atob(this.contentElements)

Here atob methods decode the pdfe and stores in the pdf object. When I retrieve 
  {{pdf}} in html then I dont get the result. But it works fineor application/xml file.

I tried to display pdf diretly from assetfolder as per online example , it worked but , I am not sure how it works in my situation.

Any pointer u have.

By the way this forum has helped me to build the concept quickly and the help I received from my previous post was really good.
Thanka a lot in advance.
Regards
Sandeep Shukla


Arnaud Deman

unread,
Jun 27, 2020, 4:17:30 AM6/27/20
to Angular and AngularJS discussion

Hi Sandeep,

in an app I do this to display a pdf generated by the backend (via ireport).
Hope this will help,
Regards
Arnaud.

Service:
loadCertificate(trainee?: Trainee) {
this.loading$.next(true);
const url = !!trainee ? `${this._url}?trainee=${trainee.login}` : this._url;
this._log.debug('CertificateService loadCertificate', url);
const headers = new HttpHeaders();
const options = { responseType: 'blob' };
return this._httpClient.get(url, { headers, responseType: 'blob' }).pipe(
tap(result => this._log.debug('result', result)),
tap(() => this.loading$.next(false)),
shareReplay()
);





Component:

this._certificateService.loadCertificate(this.trainee).subscribe(cert => {
const fileURL = URL.createObjectURL(cert);
window.open(fileURL, '_blank');
});
Reply all
Reply to author
Forward
0 new messages