Coder Social home page Coder Social logo

Comments (2)

mparizeau-pdftron avatar mparizeau-pdftron commented on July 23, 2024

Thanks for the question! In theory this might be possible, but I'll first explain a bit about how it's working right now.

When you call the WebViewer constructor that is imported from @pdftron/webviewer it will create a new iframe element and set the src to be lib/ui/index.html. This HTML file contains script tags for lib/core/CoreControls.js (WebViewer core) and lib/ui/webviewer-ui.min.js (WebViewer UI). Depending on the browser and the type of document that you load, CoreControls will load other files dynamically (e.g. WebAssembly).

Having the HTML, JS and Wasm files available statically makes things simple as we just rely on normal browser requests to load the files. All we need to do it set the src of the iframe and everything will automatically work. We can also make normal JS requests for web workers and other dynamically loaded files.

If we wanted to make it so that you would just need to install @pdftron/webviewer the simple solution would just be to bundle every single file that might possibly be loaded into a massive JS file including non-JS content. Then at runtime we would extract the HTML data as a string to set the src of the iframe and maybe the JS as well. The extracted JS would then be run in the iframe and it would extract the Wasm to load dynamically. This bundle would be quite large so we'd probably want to split this up so we can lazy load only the modules we need.

To simplify things we'd probably want to get rid of the iframe as well. This comes with its own complications around conflicting CSS, resize events, etc. In theory this should all be possible but it will require more work on our side to investigate.

Note that WebViewer has been around for ~10 years, before npm was widely used in JavaScript projects which is part of the reason why it's structured as it is. We're working on improving the usage with npm and it's good to hear your feedback.

Let me know if you have any other questions!

from webviewer-react-sample.

danantal avatar danantal commented on July 23, 2024

Sorry for the late reply. It makes more sense now.

Indeed, it would be nice to think of ways to bring this into a friendlier npm environment, but I understand the complications it brings. I guess it's fine to close this.

Thanks for all the explanations.

from webviewer-react-sample.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.