Javascript 使用javascript读取PDF文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12066118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reading PDF file using javascript
提问by Christian Eric Paran
I'm currently developing an application that would Copy/Transfer a sentence/paragraph from a PDF file to my program
. I'm using Javascript to develop my program but I have not found any idea how to read a PDF file.
我目前正在开发一个应用程序,它将Copy/Transfer a sentence/paragraph from a PDF file to my program
. 我正在使用 Javascript 来开发我的程序,但我还没有找到如何阅读 PDF 文件的任何想法。
I want to know how to Copy/Transfer a sentence/paragraph from a PDF file to my program?
我想知道如何将 PDF 文件中的句子/段落复制/传输到我的程序?
Thanks.
谢谢。
回答by Adrien Joly
I know that the question is old, but if you find PDF.js too complex for the job, npm install
pdfreader. (I wrote that module)
我知道这个问题很老,但是如果您发现 PDF.js 对这项工作来说太复杂了,npm install
pdfreader。(我写了那个模块)
It would take 5 lines of code to extract text from your PDF file:
从 PDF 文件中提取文本需要 5 行代码:
var PdfReader = require("pdfreader").PdfReader;
new PdfReader().parseFileItems("sample.pdf", function(err, item){
if (item && item.text)
console.log(item.text);
});
回答by theonlygusti
Check out PDF.js, it's a commonly used JavaScript library that contains a lot of methods for PDF manipulation.
查看PDF.js,它是一个常用的 JavaScript 库,包含许多 PDF 操作方法。
Check out this answerto see a demonstration of how to extract text using pdf.js.
查看此答案以查看有关如何使用 pdf.js 提取文本的演示。