0

I have a pdf blob like below, not complete: result: "data:application/pdf;base64,JVBERi0xLjcKCjQgMCBvYmoKKElkZW50aXR5KQplbmRvYmoKNSAwIG9iagooQWRvYmUpCmVuZG9iago4IDAgb2JqCjw8Ci9GaWx0ZXIgL0ZsYXRlRGVjb2RlCi9MZW5ndGggODg0OTIKL1R5cGUgL1N0cmVhbQo+PgpzdHJlYW0KeJzsfQlgVNXV…".

I need to view this pdf in html . Is there a possibility? Please favour

4

2 Answers 2

0

You may use PDF.js, refer to this example, it's pretty straightforward :)

0

This is solved with embed tag in html, as in "MIME encoding of a PDF file in an HTML page".

This resulted in error

"Error: unsafe value used in a resource URL context (see g.co/ng/security#xss) at DomSanitizerImpl.push../node_modules/@angular/platform-browser/fesm5/platform-browser.js.DomSanitizerImpl.sanitize (platform-browser.js:1812)"

This was later solved with Unsafe value used in a resource URL context with Angular 2 using DomSanitizer, answered by @helzgate as method 1.

Overall code:

in HTML:

<embed [src]='sanitizer.bypassSecurityTrustResourceUrl(imgURL)' height="200" *ngIf="imgURL">

In typescript,add the following in component:

import { DomSanitizer } from '@angular/platform-browser';

and

  constructor(public sanitizer: DomSanitizer) { }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.