繁体   English   中英

Pdf Reader使用Java在控制台中打印

[英]Pdf Reader prints in console using java

嗨,大家好,我想创建一个pdf阅读器,它将读取硬编码的pdf并在控制台中打印数据。我使用了以下代码。

public class pdfreader {

public static void main(String args[]) throws Exception {
    readResourceFileAndPrintContents();
}

private static void readResourceFileAndPrintContents() throws Exception {
    InputStream stream = loadResourceAsStream("/home/ajay/Downloads/Beginning iPhone Development.pdf");

    BufferedReader in = new BufferedReader(new InputStreamReader(stream));

    String line;
    while ((line = in.readLine()) != null) {
        System.out.println((line));
    }
}

public static InputStream loadResourceAsStream(final String resourceName) {
    InputStream input = null;
    try {
        input = new FileInputStream(resourceName);
    } catch (FileNotFoundException e) {
        System.out.println("Resource File Not Found");
        e.printStackTrace();
    }
    return input;
}

}

但是我没有得到上下文。 你能帮我吗。谢谢。

我曾经使用过iText,但在这里您会找到几个库。

您需要一个库来提取字符串,因为pdf不是文本,它以二进制格式保存。 需要一个库来解码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM