import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;
public class Tpdf2 {
/**
* simply reader all the text from a pdf file.
* You have to deal with the format of the output text by yourself.
* 2008-2-25
* @param pdfFilePath file path
* @return all text in the pdf file
*/
public static void main(String[] arg)
{
System.out.println(Tpdf2.getTextFromPDF("E:/person/pdf/sp.pdf"));
}
public static String getTextFromPDF(String pdfFilePath) {
String result = null;
FileInputStream is = null;
PDDocument document = null;
try {
is = new FileInputStream(pdfFilePath);
PDFParser parser = new PDFParser(is);
parser.parse();
document = parser.getPDDocument();
PDFTextStripper stripper = new PDFTextStripper();
result = stripper.getText(document);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (document != null) {
try {
document.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return result;
}
}
pdfbox 下载:
http://pdfbox.apache.org/download.html
分享到:
相关推荐
pdfbox demo 例子 其中实现了读取图片和文本,已经获得目录结构和元数据
使用pdfbox读取pdf文件的内容并转为高清图片存储至硬盘 pdfbox api,pdfbox-tools
编译得到PDFBox11.6.0的net版DLL,另外还有VS2008中使用的例子。
可用于C# 读取PDF文件,包含完整的 VS2010项目 三行代码即可读取pdf文件的所有内容,可用于WindowsForm 或者Web开发
c#使用PDFBox-0.7DLL文件转换pd成txt 命令行DOS方式 源码例子
压缩包中已经包含了所需的jar文件,一个简单的例子:SimplePDFReader.java,运行cmd_with_env.bat既可以启动cmd窗口,并自动设置好classpath, javac SimplePDFReader..java java SimplePDFReader hello.pdf
PDFBox-0.7.3 带asp.net版的dll。新版要手动编辑将java生成dll。网上的例子多是基于0.7.3版的。用7-zip压缩的,rar的21MB多。
itext pdfbox 详细的例子,其中包含 读取 解析pdf wrod 生成画格子 以及解决中文乱码问题 很多例子打包成一起 详细的注释
例子: API 文档可从 maven 中心获得。 我认为旧(2.0 之前)版本的 PDFBox 中的字符编码问题已得到修复。 因此,我删除了俄语的音译代码,该代码还将任何“高 ANSI 字符”转换为较低的 ANSI 等效字符,或者如果没有...
xpdf_支持中文pdf的解析 pdfBox 包含例子程序
java版读取解析PDF文件内容,实例中自带最新版本PDFBox.jar
参考大家学习,使用步骤和例子,压缩包中有,可以将大量图片转成pdf文件,用扫描仪扫到的图片转成pdf必用
如果生成PDF文件,大家估计会选择iText jar包,但是如果想用在一个Panel上看PDF,就要选择PDFRenderer.jar (貌似pdfbox也可以),现在将PDFRenderer jar包以及例子放到了一起,供大家参考
pdf-个性化 使用叠加和加密个性化PDF 抽象的 这是一个小工具,可通过... (注意:这需要为内部Apache PDFBox依赖项安装Java) 用法 $ pdf-personalize \ [-p ] \ [-B ] \ [-F ] \ [-O ] \ [-e ] \ [-o ] \ 例子
使用该应用程序,您可以打开和浏览 pdf 书籍。 此外,您还可以检查字符代码或定位图像。 可能是pdfbox基本使用的一个例子。
woff2ttf 将 WOFF (web) 字体转换为 TrueType (ttf) 格式 例子 <?php $woffFile = 'awesome_font.woff'; $ttfFile = 'awesome_font.ttf'; WOFF2TTF::convert($woffFile, $ttfFile);