【发布时间】:2013-04-16 11:30:07
【问题描述】:
我从服务器收到 pdf 文件。我想以只读方式打开该 pdf 文件。没有编辑选项。所以我不能使用文件操作。
哪个库最适合阅读pdf文件?
如何在java中读取pdf文件?
【问题讨论】:
-
使用 iText 或 PDFBox。谷歌搜索你的标题会导致这个链接stackoverflow.com/questions/10830583/…
我从服务器收到 pdf 文件。我想以只读方式打开该 pdf 文件。没有编辑选项。所以我不能使用文件操作。
哪个库最适合阅读pdf文件?
如何在java中读取pdf文件?
【问题讨论】:
我在使用 PDFBOX 时使用以下代码。
try
{
document = PDDocument.load(f);
document.getClass();
if( document.isEncrypted() )
{
try
{
document.decrypt( "" );
}
catch( InvalidPasswordException e )
{
System.err.println( "Error: Document is encrypted with a password." );
System.exit( 1 );
}
}
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
stripper.setSortByPosition( true );
PDFTextStripper stripper = new PDFTextStripper();
String st = stripper.getText(document);
System.out.println(st);
【讨论】: