Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

UWP displaying local pdf in pdf.js

$
0
0

All,

I had a question that I was hoping someone has run across or solved...

I am displaying local pdf's in a xamarin forms app using pdf.js.

I used the following recipe verbatim..
https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/controls/display-pdf/

It is basically working. No problem with ios, no problem with android, and for a while, no problem with UWP.

I recently set up another development machine and moved the project over to it.

Everything rebuilt fine, iOS version ran fine. Android version ran fine. But am having problems with the UWP version with regards to pdf.js.

When I try to load a local PDF I get the following error in PDF.js

PDF.js v1.5.188 (build: 0e2d50f)
Message: Unexpected server response (0) while retrieving PDF "ms-appx-web:///Assets/content/(xyz.pdf)".

I chased a number of leads on this and ultimately felt like it has to do with cross origin requests. So, to test it, I changed some of the javascript code in pdf.js.

I changed the following code snippet:
// Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
function isSameOrigin(baseUrl, otherUrl) {
try {
var base = new URL(baseUrl);
if (!base.origin || base.origin === 'null') {
return false; // non-HTTP url
}
} catch (e) {
return false;
}

var other = new URL(otherUrl, base);
return base.origin === other.origin;
}

I forced the return to always be true. The result of this is that the PDF now displays correctly.

So I think I proved it has to do with the whole cross origin stuff.

My questions are:
1. Why would this work on one windows development machine and not another? Can you set windows (browsers) to somehow allow cross origin and therefore it works on one machine but not the other?
2. Does the xamarin recipe for displaying local pdf's not work anymore because pdf.js has changed?
3. Is forcing the cross site thing to true in pdf.js a terrible idea?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>