Extracting Hebrew text from PDF using apache pdfbox does not return all characters

倾然丶 夕夏残阳落幕 提交于 2020-01-15 11:29:09

问题


The code below extracts Hebrew text from http://www.language-brain.com/journal/docs/Gvion_Friedmann_LanguageBrain7_frigvi.pdf without the Hebrew character "ן". All other text seems to be extracted fine. Any ideas?

public class TestPDFUtil {
    @Test
    public void testHebrewPDF() throws Exception {
        String url = "http://www.language-brain.com/journal/docs/Gvion_Friedmann_LanguageBrain7_frigvi.pdf";
        String text = PDFUtil.readPDF(url);
        System.out.println(text);
        Assert.assertTrue(text.indexOf("זיכרון עבודה") != -1);
    }
}

public class PDFUtil {
    public static String readPDF(String url) throws IOException {
        URL urlObj = new URL(url);
        PDDocument document = PDDocument.load(urlObj.openStream());
        document.getClass();
        if( !document.isEncrypted() ){
            PDFTextStripper stripper = new PDFTextStripper();
            String text = stripper.getText(document);
            document.close();
            return text.trim();
        }
        return null;
    }
}

Attaching screen shots that show the missing character. On the left is how the page http://www.language-brain.com/journal/docs/Gvion_Friedmann_LanguageBrain7_frigvi.pdf appears in Crome. On the right is the result of PDF text extraction using the code above.

来源:https://stackoverflow.com/questions/43901609/extracting-hebrew-text-from-pdf-using-apache-pdfbox-does-not-return-all-characte

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!