如何从javascript中的pdf文件中提取文本? [英] How to extract text from a pdf file in javascript?

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

问题描述

所以我想知道是否有办法在 javascript 中从 pdf 中提取文本?我已经调查了一些 npm 模块,例如 PDF-TO-TEXT,但它们都将文件路径名作为输入.我正在使用 react-drop-to-upload 模块来允许用户将 pdf 放到 react 组件中.react 组件接收 pdf 文件并返回一个 File 对象而不是文件路径.有没有办法将存储在 File 对象中的 PDF 转换为文本?谢谢!

So I am wondering if there's a way to extract text from pdf in javascript? I have already surveyed some npm modules like PDF-TO-TEXT but they all take in a file path name as input. I am using the react-drop-to-upload module to allow the user to drop the pdf to a react component. The react component takes in the pdf file and returns a File object rather than a file path. Is there a way to convert PDF stored in an File object to text? Thanks!

推荐答案

PDF.js 允许您加载文件对象,然后将文档解析为文本.这个 example 来自官方网站正是这样做的.

PDF.js allows you to load file objects and then parse the document as a text. This example from the official website does exactly that.

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

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