如何在react-native中从pdf文件中提取内容 [英] How to extract content from pdf file in react-native

查看:61
本文介绍了如何在react-native中从pdf文件中提取内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个个人项目,我想要一个功能,我可以从文件系统中提取一个 pdf 文件并通过任何方式读取它的内容.

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.

顺便说一下,我正在 ios 上进行测试.

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>

例如运行此代码会产生 -> null is not an object(评估 RNFSManager.RNFSFileTypeRegular)

running this code for example yields in -> null is not an object (evaluating RNFSManager.RNFSFileTypeRegular)

任何帮助将不胜感激.

推荐答案

我刚刚解决了这个问题.你需要做的

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

这篇关于如何在react-native中从pdf文件中提取内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆