Blazor Interop for Mozilla pdf.js

DinoN 1 Reputation point
2021-07-18T17:16:17.257+00:00

Anyone managed to create a JS interop for https://github.com/mozilla/pdf.js
I am looking for robust viewer solution to show PDF files.

Thank you,
D

Developer technologies | .NET | Blazor
{count} votes

4 answers

Sort by: Most helpful
  1. Anonymous
    2021-07-30T09:41:17.263+00:00

    Hi @DinoN

    The easiest way is to use the following method is to display the pdf file.

    Method 1

    Use iframe with below code. And the url is http://docs.google.com/gview?url=http://yourwebapp/file1.pdf&embedded=true.

    119299-image.png

    It works on my side.

    119316-9.gif

    Method 2

    You can refer to official doc about pdf.js. It will useful to you.

    How to Embed a PDF in an HTML Website


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,
    Jason

    0 comments No comments

  2. Bruce (SqlWork.com) 77,851 Reputation points Volunteer Moderator
    2021-12-04T04:30:12.9+00:00

    The blazor code should define the canvas. The using the sample

    https://mozilla.github.io/pdf.js/examples/index.html#interactive-examples

    Create a JavaScript file that is included that has a public method blazor interop can call passing the url.

    Note: blazor could make the ajax call but it’s more efficient for the JavaScript to do. After all webclient will call JavaScript anyway. Even if blazor server, you would need to use base64 encoded pdf which would make the payload larger.

    0 comments No comments

  3. Santiago Alfonso 1 Reputation point
    2021-12-06T15:29:59.707+00:00

    This works great for small pdf's, but unfortunately there's a limit on the Base64 in the browsers. When I try the example with a 2.21MB file it doesn't load.

    0 comments No comments

  4. Frank Mehlhop 66 Reputation points
    2022-07-18T14:50:29.497+00:00

    @DinoN @Santiago Alfonso

    Has any body successful implemented pdfjs in a Blazor App for all pdf sizes?
    What are the steps to do so?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.