Displaying pdf files from internet in Xamarin.Forms UWP

dpreznikdpreznik Member ✭✭

I have a Xamarin.Forms application supporting only UWP. I need to be able to load pdf files from the web and display the content in my application. I cannot find a solution that would work with UWP and handle pdf files that are not part of a project. Please help.

Best Answers

Answers

  • dpreznikdpreznik Member ✭✭

    @YorkGo said:
    Try using Nico's solution:

    Actually, I tried it before, and it did not work. I don't know if I did something wrong. Does WinPhone81 work as UWP?

  • dpreznikdpreznik Member ✭✭

    I realized that the description says, "The code assumes that the file is stored in the Assets/Content folder of the project."

    But my pdfs should be taken right from the web...

  • dpreznikdpreznik Member ✭✭

    I am getting an error: Message: file origin does not match viewer's. I tried another file with the same result. Could you please tell what is wrong?

  • GaetanFGaetanF USMember ✭✭✭

    There is also this quite good tutorial which covers the subject A to Z. Combined with @YorkGo's answer, you will be able to get it right.

  • dpreznikdpreznik Member ✭✭

    @GaetanF said:
    There is also this quite good tutorial which covers the subject A to Z. Combined with @YorkGo's answer, you will be able to get it right.

    This tutorial doesn't seem to cover UWP. The 2019 solution for Android mentioned there would not compile for UWP:
    e.g.
    'WebViewSettings' does not contain a definition for 'AllowUniversalAccessFromFileURLs' and no accessible extension method 'AllowUniversalAccessFromFileURLs' accepting a first argument of type 'WebViewSettings' could be found (are you missing a using directive or an assembly reference?)

  • GaetanFGaetanF USMember ✭✭✭

    Well I said the knowledge from this tutorial and the solution provided by @YorkGo will lead you to the right solution, not that you just need to copy paste the solution from the tutorial.

  • dpreznikdpreznik Member ✭✭

    @GaetanF said:
    Well I said the knowledge from this tutorial and the solution provided by @YorkGo will lead you to the right solution, not that you just need to copy paste the solution from the tutorial.

    I am afraid I don't know enough to be able to use it.

  • GaetanFGaetanF USMember ✭✭✭
    edited January 18

    @dpreznik said:

    @GaetanF said:
    Well I said the knowledge from this tutorial and the solution provided by @YorkGo will lead you to the right solution, not that you just need to copy paste the solution from the tutorial.

    I am afraid I don't know enough to be able to use it.

    In that case, take your time to learn because there is no other way, except make someone else to do it. Have a look on Xamarin Custom Renderers documentation and this tutorial on custom controls. And if you still stumble on taught principle in these tutorials then keep digging them.

  • sergtksergtk Member
    edited February 8

    @GaetanF said:
    Well I said the knowledge from this tutorial and the solution provided by @YorkGo will lead you to the right solution, not that you just need to copy paste the solution from the tutorial.

    The issue with UWP is that pdf.js assets have scheme "ms-appx-web://" and local pdf file is "file://". As a result pdf.js emits error "file origin does not match viewer's".

    There is not such error for Android, because assets and files are in the same scheme "file://".

    There is no such issue for pdfs from assets under UWP, because they both have scheme "ms-appx-web://".

    So actually the tutorial is hardly may be helpful, because the issue is specific to UWP with local pdf files, which are not assets.

    If somebody know how to overcome this issue, it would be very helpful.

    Thank you.

Sign In or Register to comment.