Apache Tika로 텍스트를 추출하기 위해 PDF 파일을 구문 분석하고 있습니다.Apache Tika를 사용하여 text/PDF에서 특수 문자를 제거하십시오.
//Create a body content handler
BodyContentHandler handler = new BodyContentHandler();
//Metadata
Metadata metadata = new Metadata();
//Input file path
FileInputStream inputstream = new FileInputStream(new File(faInputFileName));
//Parser context. It is used to parse InputStream
ParseContext pcontext = new ParseContext();
try
{
//parsing the document using PDF parser from Tika.
PDFParser pdfparser = new PDFParser();
//Do the parsing by calling the parse function of pdfparser
pdfparser.parse(inputstream, handler, metadata,pcontext);
}catch(Exception e)
{
System.out.println("Exception caught:");
}
String extractedText = handler.toString();
위의 코드 작업과 PDF의 텍스트는 인용되어 있습니다.
일부 특수 문자가 @/&/£ 또는 상표 기호 등의 PDF 파일에 있습니다. 추출 과정에서 또는 추출 과정 후에 특수 문자를 어떻게 제거 할 수 있습니까?
W를 문자열에 정규식이 있습니까? [String.replace] (https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replace (java.lang.CharSequence, % 20java.lang.CharSequence))? – Gagravarr