2634
Views
9
Comments
[pdfJS Viewer] How to view PDF from different origin or different hostname?
Question
pdfjs-viewer
Web icon
Forge asset by Eduardo Jauch

Got this error...


2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Harlin,

Did you try to investigate yourself at all? I know nothing about this component, but if I type "PDF.js f" in Google, it automatically offers the suggestion "file origin does not match viewer's", and when searching for that there's a lot of info.

2024-03-25 06-19-08
Harlin Setiadarma

Yes I did, but I am not Javascript programmer.

All answers I got from google was to comment out that logic that check the file origin in the minified javascript.

I don't know how to do that.

2020-02-28 09-46-54
Eduardo Jauch

Hello Harlin,

I'll see if I can put a configuration allowing for this in the component.

As soon as I'm able to do that, I'll let you know here. 

Cheers

P.S. probably today I'll have news on this.

2024-03-25 06-19-08
Harlin Setiadarma

Thanks a lot.

2020-02-28 09-46-54
Eduardo Jauch

Hello Harlin,

I was investigating the issue. I remember that we have a HostsList in the component.
It is meant to defined the hosts that are allowed to see the PDF, if the PDF is not in the application's host.

So, if both application's and pdf file's hosts are under control, you can add your application host www.yourapplication.com to this list (when calling the Viewer screen, through the HostsList parameter). 

Unfortunatelly, this will work ONLY if the PDF source has your host marked as a permitted requester (through the header Access-Control-Allow-Origin). 

So, if you do not control the host were the PDF is installed nor the owners whitelist your host, the browser will not allow you to fetch the resource. 

This is a Browser's security feature that I think you can't workaround.

Cheers.

2024-03-25 06-19-08
Harlin Setiadarma

I've tried the HostsList before, but it still didn't work.

Please elaborate on the header Access-Control-Allow-Origin.

I know I can add the header using HttpRequestHandler's AddHeader action.

But what value should I put in there.

2020-02-28 09-46-54
Eduardo Jauch

Hello  Harlin,

This header must be placed in the URL of the PDF, not in your application. 

It is not possible to download, through your application, any resource from a domain other than the domain your application is, unless the domain where the resource is say (through that header in the response) that your domain is allowed.

Cheers

2024-03-25 06-19-08
Harlin Setiadarma

Ok, I got it now.

I will notify the owner of pdf page.

What value should be put in the header?

Thanks. 

2020-02-28 09-46-54
Eduardo Jauch

Hi Harlin,

Here you see syntax and examples: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin

Than, in the HostsList property, you put your domain.

Cheers

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.