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

Cant install Pdf.JS on React Native #8774

Closed
diogoviannaaraujo opened this issue Aug 13, 2017 · 10 comments
Closed

Cant install Pdf.JS on React Native #8774

diogoviannaaraujo opened this issue Aug 13, 2017 · 10 comments

Comments

@diogoviannaaraujo
Copy link

Configuration:

  • MacOS and Node 8.x
  • React Native

Steps to reproduce the problem:

  • Start a react native project
  • Yarn add pdfjs-dist
  • Try to import pdfjs-dist

You will get a error like this

Unable to resolve module ./zlib_bindings ./node_modules/zlib/lib/zlib_bindings doesn't exist

@timvandermeij
Copy link
Contributor

zlib should be available in Node.js. IIRC zlib is only used for the experimental SVG back-end for optimizations, so I'm not sure why you're getting this. Does npm install zlib work? If it does, perhaps we need to add it to the devDependencies in package.json?

@yurydelendik
Copy link
Contributor

Please provide complete example.

@yurydelendik
Copy link
Contributor

Actually, I'll close it won't fix. Even if we will solve zlib_binding, there is no guarantee rest of PDF.js will work -- PDF.js need "native" browser's DOM to work.

@diogoviannaaraujo
Copy link
Author

React Native code does not run on a full node.js environment, so zlib is not available by default.

If I just add pdfjs-dist to package.json it goes to a zlib com not be found error.
Then I added https://www.npmjs.com/package/zlib

And got that error,
I think it should threat React Native as a browser js not as a node

@flieks
Copy link

flieks commented Aug 22, 2017

is it possible to use webGL to achieve this ?

@yurydelendik
Copy link
Contributor

is it possible to use webGL to achieve this ?

Anything is possible -- you just need to implement logic similar to what src/display/canvas.js or src/display/svg.js implements.

@flieks
Copy link

flieks commented Aug 23, 2017

Haha thanks you but those files are 2000 lines of code and my webGL knowledge is nihil :)

Also pdfjs doesn't work well with expo yet (zlib). Neither webview

https://github.com/expo/expo-sdk/issues/82

@diogoviannaaraujo
Copy link
Author

diogoviannaaraujo commented Aug 23, 2017 via email

@flieks
Copy link

flieks commented Aug 24, 2017

yes, Expo doesn't have way to show PDF right now and neither has PDF.js.
I will use https://github.com/wonday/react-native-pdf and will have to detach from Expo i fear. Don't really want to detach but there is no other easy way

@agilgur5
Copy link

Was looking into this myself, so figured I might leave some notes for future readers.
Initially I found https://github.com/iddan/react-native-canvas which could move a step forward in at least getting rendering to work. It uses a WebView under the hood.
When looking into WebView support, I did find this issue: #7157 (comment) , and the comment which points to https://github.com/xcarpentier/rn-pdf-reader-js , which was actually built for Expo. It similarly uses a WebView under the hood (and uses react-pdf instead of pdf.js directly)

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

No branches or pull requests

5 participants