有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

pdfbox提取的java文本包含奇怪的问号符号来代替空格

当我尝试使用ApachePDFBOx2.0.18从PDF中提取文本时,输出如下所示:

enter image description here

我怎样才能避免那些问号符号? 下面是我的pdf提取方法

 public static String getPDFContent(File pdfFile) throws IOException {
    PDDocument doc = null;
    String text = null;
    try {
        doc = PDDocument.load(pdfFile);
        text = new PDFTextStripper().getText(doc);
    }
    catch (Exception e) {
        logger.error("An exception occurred while extracting text from pdf using Apache PDFBox.");
        return null;
    }
    finally {
        if( doc != null )
        {
            doc.close();
        }
    }
    return text;
}

共 (0) 个答案