问题
I am working on a personal project where I want to have a functionality where I can pick up a pdf file from the file system and read the content of it by ANYHOW.
I tried every possible library out there but nothing works and most of them no support any more whatsoever.
I am testing on ios by the way.
an example of my standpoint would be like:
<View style={styles.buttonPdfContainer}>
<Image style={styles.pdfIcon} source={require('../resources/pdf.png')}/>
<TouchableOpacity onPress={() => {
// navigation.navigate('Info')
var RNFS = require('react-native-fs');
const pdf = require('pdf-parse');
let dataBuffer = RNFS.readFileSync('path to PDF file...');
pdf(dataBuffer).then(function(data) {
// number of pages
console.log(data.numpages);
// number of rendered pages
console.log(data.numrender);
// PDF info
console.log(data.info);
// PDF metadata
console.log(data.metadata);
// PDF.js version
// check https://mozilla.github.io/pdf.js/getting_started/
console.log(data.version);
// PDF text
console.log(data.text);
});
}}>
<Text style={styles.manualText}>with Notenspiegel pdf</Text>
</TouchableOpacity>
</View>
running this code for example yields in -> null is not an object (evaluating RNFSManager.RNFSFileTypeRegular)
any help would be appreciated.
回答1:
I have just fixed this issue. You need to do
npm unlink react-native-fs //If react-native < 0.60.x
npm uninstall react-native-fs
npm install react-native-fs
npx react-native run-android
来源:https://stackoverflow.com/questions/57435198/how-to-extract-content-from-pdf-file-in-react-native