Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying mupdf library directly with React #12

Open
jamie-lemon opened this issue Feb 12, 2024 · 3 comments
Open

Trying mupdf library directly with React #12

jamie-lemon opened this issue Feb 12, 2024 · 3 comments
Assignees
Labels

Comments

@jamie-lemon
Copy link
Collaborator

With this setup we can run a React-based app via a node server, so basically a REST API provided by the node server to the react client.

react-via-node-server

However, if we just want to run a React-based app directly upon the MuPDF library, i.e.:

react-direct

It fails to compile with:

./node_modules/mupdf/lib/mupdf-wasm.js:130:7
Module not found: Can't resolve 'fs'

Could there be some further environmental setup that the wasm library needs to understand?

@jamie-lemon
Copy link
Collaborator Author

@ccxvii @mipo1357 Please note I create a simple React App starter for this, please see this branch: https://github.com/ArtifexSoftware/mupdf.js/tree/react-example . You can see the compile problem after an npm start . There is hopefully something obvious I'm doing wrong.

@jamie-lemon
Copy link
Collaborator Author

@ccxvii it could be that the solution here could work for us, requires further investigation:
emscripten-core/emscripten#13074

@Vilhelm-Ian
Copy link

I got mupdf to work with react with the following approach.

i import this in the index.html

<script type="module" src="/mupdf-view.js"></script>
<script type="module" src="/mupdf-view-page.js"></script>
import { MupdfDocumentViewer } from "../mupdf-view-page.js"


function Reader() {

useEffect(()=>{
   new MupdfDocumentViewer(mupdfView)
},[])

return (
                <div id="reader">
                    <div id="grid-sidebar">
                        <ul id="outline" />
                    </div>
                    <div id="grid-main" class="sidebarHidden">
                        <div id="pages" />
                        <div ref={placeholder} id="placeholder">
                            <div>Loading WASM, please wait...</div>
                        </div>
                    </div>
                    <div
                        id="search-dialog"
                        class="dialog"
                        style="display: none"
                    />
                    <input
                        type="file"
                        id="open-file-input"
                        style="display: none"
                        accept=".pdf,.xps,application/pdf"
                        onChange={(e) => {
                            documentViewer.openFile(e.target.files[0])
                        }}
                    />
)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants