2

I cannot get my pdf to display on viewer via url in typescript. I am using ngx-extended-pdf-viewer

Here is an example of my code with the URL replaced.

<ngx-extended-pdf-viewer 
*ngIf="!isFirefox"  
  [src]="'http://www.childrensbooksforever.com/Childrenpics/A%20COOL%20KID%20LIKE%20ME.pdf'"
  useBrowserLocale="true" 
  backgroundColor="#000000" 
  height="100%">            
</ngx-extended-pdf-viewer>

Error message in the viewer:

PDF.js v2.1.266 (build: 81f5835c)
Message: Failed to fetch

in the pdf viewer.

I can view the pdf if i place it in the assets folder but the url doesn't work. An empty frame is shown. What am I doing incorrectly?

Stephan Rauh
  • 3,069
  • 2
  • 18
  • 37
new_to_01
  • 21
  • 1
  • 3
  • the errors are quite self-explanatory buddy. The 1st error says that the object whose property `clientHeight` you're referring to is undefined. And regarding the second, [this gitHub discussion](https://github.com/stephanrauh/ngx-extended-pdf-viewer/issues/20) might help you. – Harshith Rai Jun 28 '19 at 09:38
  • This seems to be the same issue as https://github.com/stephanrauh/ngx-extended-pdf-viewer/issues/98. – Stephan Rauh Jul 06 '19 at 20:57

1 Answers1

0

I can only guess, but my most likely explanation is "CORS". Modern browsers protect you against a certain class of hacker attacks by refusing to download or send stuff from another URL.

You've mentioned accessing local file works, so chances are using a proxy will fix the problem. For example, there's the proxy-conf.json in the Angular CLI.

Stephan Rauh
  • 3,069
  • 2
  • 18
  • 37
  • One question about this one, say you have the pdf viewer embedded inside the iframe and iframe and parent window are from different origins, would the browser allow download functionality? – The.Wolfgang.Grimmer Mar 07 '22 at 01:06