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

component doesn't render #15

Closed
kristkirp opened this issue Jun 13, 2018 · 25 comments
Closed

component doesn't render #15

kristkirp opened this issue Jun 13, 2018 · 25 comments

Comments

@kristkirp
Copy link

kristkirp commented Jun 13, 2018

Hi i have following versions:

"devDependencies": {
"jest-expo": "27.0.0",
"react-native-scripts": "1.11.1",
"react-test-renderer": "16.2.0"
},
"dependencies": {
"expo": "^27.0.0",
"react": "^16.3.1",
"react-native": "^0.55.4"
}

"expo": {
"sdkVersion": "27.0.0",
}

The component doesn't give any error just nothing. The problem is not in uri/base64 they are fine, i tried uri from your example

This is the code:
KeyboardAvoidingView keyboardVerticalOffset={80} behavior="padding" style={{ flex: 1 }}
ScrollView style={{ flex: 1 }}
View style={{ flex: 1,
paddingTop: Constants.statusBarHeight}}>
<PDFReader
source={{ uri: "http://gahp.net/wp-content/uploads/2017/09/sample.pdf" }}
/>
View
ScrollView
KeyboardAvoidingView

Thank you

upd: the full code not displayed i don't know why, it displays only in edit mode

@xcarpentier
Copy link
Owner

What do you mean by display only on edit mode?

@kristkirp
Copy link
Author

I updated code in questions, had to remove "<" and "/>" because it doesn't show fully with with them

@kristkirp
Copy link
Author

So my PDFReader is inside View, ScrollView, KeyboardAvoidingView

@xcarpentier
Copy link
Owner

iOS or android ?
On device or emulator ?
If you use it only into <View/> does it works?

For now I recommend to use this component in full screen.

@xcarpentier
Copy link
Owner

Can you provide a screenshot?

@kristkirp
Copy link
Author

When it is wrapped in just a View it works! Thank you for help! :)

@xcarpentier
Copy link
Owner

@Sanj98
Copy link

Sanj98 commented Dec 26, 2018

Hi
The component does not render and your index.js file throws errors as below
which says "[js] 'types' can only be used in a .ts file."
erros

PLEASE HELP ME OUT

@ghost
Copy link

ghost commented Jan 9, 2019

Hi there, I keep getting this error:
"console.error: Unable to get result of file due to bad type, waiting string and getting object."
Could some assist please? I will provide more info if needed.

This is what is pass to the PDFReader:

<PDFReader
source={{ uri: "http://gahp.net/wp-content/uploads/2017/09/sample.pdf" }}
/>

My package.json:
{
"name": "empty-project-template",
"main": "node_modules/expo/AppEntry.js",
"private": true,
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"eject": "expo eject"
},
"dependencies": {
"axios": "^0.18.0",
"expo": "^31.0.6",
"lodash": "^4.17.11",
"moment": "^2.22.2",
"moment-timezone": "^0.5.23",
"native-base": "^2.8.1",
"prop-types": "^15.6.2",
"react": "16.5.0",
"react-moment": "^0.8.4",
"react-native": "https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz",
"react-native-datepicker": "^1.7.2",
"react-native-fetch-blob": "^0.10.8",
"react-native-modal-dropdown": "^0.6.2",
"react-native-popup-dialog": "^0.16.6",
"react-native-vector-icons": "^6.0.2",
"react-navigation": "^2.17.0",
"react-redux": "^5.0.7",
"redux": "^4.0.0",
"redux-thunk": "^2.3.0",
"rn-pdf-reader-js": "^0.1.7"
}
}

@fabiendeborde
Copy link

I am having the same issue as the one described above.
The code was working a few weeks ago and today when I came back to debug another part of the app I realized the PDF Reader was broken.
I tried to render the code below instead to be sure I didn't mess something with my URI but I still code the same error message.
<PDFReader source={{ uri: 'http://gahp.net/wp-content/uploads/2017/09/sample.pdf' }} />

Could it be related to the upgrade to expo 31?

@thiagosouzasi
Copy link

Hello guys, I solved the display problem by adding the following code inside the styles

pdf: {
width: Dimensions.get ('window'). width,
height: Dimensions.get ('window'). height,
},

@Jayeshkarma
Copy link

`import React, { memo } from 'react';
import { View, StyleSheet, Dimensions } from 'react-native'
import PDFReader from 'rn-pdf-reader-js'
const LearningScreen = props => {

return( 
  <View style={styles.container}> 
    <PDFReader style={styles.pdf}
      source={{
        uri: 'http://gahp.net/wp-content/uploads/2017/09/sample.pdf',
      }}
    />
  </View> 
)

}
const styles = StyleSheet.create({
container:{
justifyContent:'center',
flex:1,

      backgroundColor:'red'
  },

  pdf: {
    width: Dimensions.get ('window'). width,
    height: Dimensions.get ('window'). height,
    backgroundColor:'#000'
    },
});

export default memo(LearningScreen);`

not showing anything on screen please help me to solve it

@xTurbeaux
Copy link

does anyone use the headers? cant get mine to track to the desired destination set on the pdf, honestly Im not even sure if I have this configured properly

<View style={{width: '100%', height: '100%'}}>
<PDFReader
source={{
uri: 'http://10.1.10.167:5501/docs/Product_Guide_2020.pdf#hearth',
headers: { ['hearth']: 'http://10.1.10.167:5501/docs/Product_Guide_2020.pdf#hearth' }
}}
/>

@Vishal-Ramanlal
Copy link

Does the work while the device is offline. The following code is what i use.
<PdfReader style={styles.pdf} source={{ uri: path }} />

the path being from the filesystem i.e. file://path.
This code works when the device is online however when i turn of data and wifi, it doesn't load the pdf. Any solutions?

@monizb
Copy link

monizb commented Aug 5, 2021

Does the work while the device is offline. The following code is what i use.
<PdfReader style={styles.pdf} source={{ uri: path }} />

the path being from the filesystem i.e. file://path.
This code works when the device is online however when i turn of data and wifi, it doesn't load the pdf. Any solutions?

Were you able to fix this?

@AlacranBlanco
Copy link

AlacranBlanco commented Aug 27, 2021

i tried "<View>" but it didn't work, but i use a template tag "<>" and it works

@monizb
Copy link

monizb commented Aug 27, 2021

Does the work while the device is offline. The following code is what i use.
<PdfReader style={styles.pdf} source={{ uri: path }} />

the path being from the filesystem i.e. file://path.
This code works when the device is online however when i turn of data and wifi, it doesn't load the pdf. Any solutions?

So on closely looking at the code I realized that offline pdf will load from your local file storage but the Pdf viewer itself requires an internet connection to load CDN files, so the device has to be online

@AlacranBlanco
Copy link

AlacranBlanco commented Aug 27, 2021

Hi!

NOTE: Please read docs from EXPO about FileSystem before continue reading this: https://docs.expo.dev/versions/latest/sdk/filesystem

I did my "best" approach to play the reader OFFLINE/ONLINE loading files https:// or file://;

1 .- You have to download the CDN the first time that user use the APP, then save it in the storage using FileSystem, obviously the first time that our user use the app it has to be ONLINE

I did this in my App.js, this is my first screen to render in my app

image

2 .- Then you have to edit the index.js file of the module "rn-pdf-reader-js" like this, this means that were always loading CDN from our device no from internet

image

2.1 .- Edit the HTML like this

image

3 .- And voilà, you can actually render the PDF reader OFFLINE this only works with files that are store in our device (ie. file://)

WhatsApp Image 2021-08-26 at 11 58 22 PM

I KNOW THAT THIS IS NOT THE BEST OPTION BUT THIS IS A GOOD WORKAROUND TO SOLVE THIS

I KNOW THAT THIS MODULE WILL CHANGE EVERYTIME THAT WE RUN "NPM INSTALL", THIS MEANS THAT "index.js" WILL NOT WORK TILL WE CHANGE IT AGAIN (STEP #2)

THANKS TO @monizb for the feedback

@monizb
Copy link

monizb commented Aug 27, 2021

That's a brilliant workaround!

@sylvio-ruiz
Copy link

sylvio-ruiz commented Mar 15, 2022

Hi!

NOTE: Please read docs from EXPO about FileSystem before continue reading this: https://docs.expo.dev/versions/latest/sdk/filesystem

I did my "best" approach to play the reader OFFLINE/ONLINE loading files https:// or file://;

1 .- You have to download the CDN the first time that user use the APP, then save it in the storage using FileSystem, obviously the first time that our user use the app it has to be ONLINE

I did this in my App.js, this is my first screen to render in my app

image

2 .- Then you have to edit the index.js file of the module "rn-pdf-reader-js" like this, this means that were always loading CDN from our device no from internet

image

2.1 .- Edit the HTML like this

image

3 .- And voilà, you can actually render the PDF reader OFFLINE this only works with files that are store in our device (ie. file://)

WhatsApp Image 2021-08-26 at 11 58 22 PM

I KNOW THAT THIS IS NOT THE BEST OPTION BUT THIS IS A GOOD WORKAROUND TO SOLVE THIS

I KNOW THAT THIS MODULE WILL CHANGE EVERYTIME THAT WE RUN "NPM INSTALL", THIS MEANS THAT "index.js" WILL NOT WORK TILL WE CHANGE IT AGAIN (STEP #2)

THANKS TO @monizb for the feedback

Are you sure that FileSystem.readDirectoryAsync will return an array on the same file order that you dowload them? If not the pdfjsLib.GlobalWorkerOptions.workerSrc can get the wrong destination source. You must to make sure where they are before passing them to the scripts tags and off course to the key (workerSrc) above. So you must to reorder the array.

await writeAsStringAsync(htmlPath, viewerHtml(data, customStyle, withScroll, withPinchZoom, maximumPinchZoomScale, cndList.sort()));

So the cdnList will return the alphabetic order, even if it was not, and you will know exactly where is the index for each filepath.

So, if you do not want to change the indexes that you already added to the in the index.js, just add a prefix to each file when you created them to dowload like rn1-, rn2- , rn3-, rn4-, rn5- and prepend them in each file since they are on the same order that you added them to the index.js, but keep the cndList.sort(), just to be sure they will be where we want.

Another solution is do the same thing that xcaperntier did, embed each js file as base64 on the bundleContainer and call a function to decode the string and write it to a file with a name that you wish and add it to the source of html. In this case, the pdf viewer will work even the user open it first time without a connection. xcarpentier save and remove it when the component will unmount, but you can leave them there.

Good solution, thank you.

Great work!

@visharma14
Copy link

why my hooks dosent render a pdf by using fetch api in rn-pdf-reader-js . please help i'm new in this native

@thecompoundingdev
Copy link

thecompoundingdev commented Aug 5, 2022

@AlacranBlanco
Hi Alacran! I'm having some trouble displaying the viewer with a base64 pdf. You seem like you've figured this package out pretty well- I'd love to chat with you for a few minutes!

@alt2cl
Copy link

alt2cl commented Sep 26, 2023

Is this project compatible with SDK 49?

@mktspace
Copy link

mktspace commented Nov 2, 2023

Seeing error with SDK 49. Has anyone tried using with SDK49.

Error: Cannot convert value to null object

Works fine with SDK48. WebView package dependency seem like

@kirtikapadiya
Copy link

kirtikapadiya commented Jan 23, 2024

@mktspace I also found same issue on expo SDK 49
Its not working in android device.
Reproducible snack demo : https://snack.expo.dev/@kirtikk/pdfreader-expo-49?platform=android

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