+ -
当前位置:首页 → 问答吧 → 想从PDF档案中抽当中想要文字

想从PDF档案中抽当中想要文字

时间:2014-03-18

来源:互联网

想从PDF档案中search个keyword, 然后copy keyword后面若干个字出来. 因档案成千个, 每个档只系要十多行字, 用肉眼睇有排

小弟试个用php pdf phaser, 但只要pdf入面keyword多个一个, 就抽错晒

各位高手请问除左php, 仲有冇api or language 可以处理到抽到pdf既文字? 大家有冇类似经验或遇上同样情况?

我见其实好多文件都用pdf, 文件一多, 如果可以自动抽到当中想要文字系好方便.

作者: leefrk17   发布时间: 2014-03-18

If you are java programmer, you can try pdfbox library.
http://pdfbox.apache.org/

作者: McLoneIII   发布时间: 2014-03-18

引用:原帖由 leefrk17 於 2014-1-19 05:27 AM 发表
想从PDF档案中search个keyword, 然后copy keyword后面若干个字出来. 因档案成千个, 每个档只系要十多行字, 用肉眼睇有排

小弟试个用php pdf phaser, 但只要pdf入面keyword多个一个, 就抽错晒

各位高 ...
http://itextpdf.com/product/itext
Download itextsharp.dll, 果度有API 畀你睇点用, 除左.net, Java 都有
Powershell:
复制内容到剪贴板代码:Add-Type -Path .\itextsharp.dll

$pdfs = (gci . -include "*.pdf" -recurse)
foreach($pdf in $pdfs) {

[string[]]$Text = $null
$reader = New-Object iTextSharp.text.pdf.pdfreader -ArgumentList $pdf.FullName
for ($page = 1; $page -le $reader.NumberOfPages; $page++) {

$strategy = new-object 'iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy'
$pageText = [iTextSharp.text.pdf.parser.PdfTextExtractor]::GetTextFromPage($reader, $page, $strategy);
$Text += $pageText.split("`n")
}
$reader.Close();
$Text | select-string "hello world"
}
当你抄左去 current directory, 响 current directory 下面揾哂*.pdf, search "hello world"

作者: lohengrin   发布时间: 2014-03-18