dip s

dip s

  • NA
  • 256
  • 81.7k

How to Embed PDF data (Base 64) in angular 6 component

Sep 23 2020 7:15 AM
Hi,
In my application in angular 6,  I am showing Data(Report) in new window as follows. 
  1. *** result contains Base64 data***    
  2.     
  3. if (result != null) {    
  4.                   
  5.               const pdfWindow = window.open("");    
  6.               pdfWindow.document.write("<html<head><title>Pathology Report</title><style>body{margin: 0px;}iframe{border-width: 0px;}</style></head>");    
  7.               pdfWindow.document.write("<body><embed width='100%' height='100%' src='data:application/pdf;base64, " +    
  8.                   encodeURI(result) + "#toolbar=0&navpanes=0&scrollbar=0'></embed></body></html>")   
 Now what I want to do is like, I want to embed this data(result) in my angular component in <iframe> or <embed> tag.
My html code is as follows
  1. <iframe [src]="PathReportString"></iframe>  
and component.ts code is 
  1. this.PathReportString = (this.sanitizer.bypassSecurityTrustResourceUrl(result) as any).changingThisBreaksApplicationSecurity;  
But it shows error "unsafe value used in a resource URL context" 
How to embed data to component. Also my data is base64.  
What is going wrong? Any help would be appreciated. Thank you. 

Answers (2)