【问题标题】:How to Read PDF file in Java? [closed]如何在 Java 中读取 PDF 文件? [关闭]
【发布时间】:2013-04-16 11:30:07
【问题描述】:

我从服务器收到 pdf 文件。我想以只读方式打开该 pdf 文件。没有编辑选项。所以我不能使用文件操作。

哪个库最适合阅读pdf文件?

如何在java中读取pdf文件?

【问题讨论】:

标签: java pdf


【解决方案1】:

使用PDFBOXiText

我在使用 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);

【讨论】:

    猜你喜欢
    • 2011-06-14
    • 1970-01-01
    • 2011-11-11
    • 1970-01-01
    • 1970-01-01
    • 2012-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多