toklin 读取word,pdf文件
toklin 读取word,pdf文件
//org.apache.pdfbox:pdfbox:2.0.36
val file = File("input.pdf")
val pdDocument = PDDocument.load(file)
val pdfTextStripper = PDFTextStripper()
val fullText = pdfTextStripper.getText(pdDocument)
println(fullText)
//org.apache.poi:poi-ooxml:5.5.1
val textContent = StringBuilder()
val filePath = File("input.docx")
try {
FileInputStream(filePath).let { fis ->
XWPFDocument(fis).use { document ->
val paragraphs: MutableList<XWPFParagraph> = document.getParagraphs()
for (paragraph in paragraphs) {
textContent.append(paragraph.getText()).append("\n")
}
}
}
} catch (e: IOException) {
e.printStackTrace()
}
println("textContent:$textContent")
参考:https://www.oryoy.com/news/android-gao-xiao-jie-xi-word-wen-dang-shi-yong-java-shi-xian-wen-dang-du-qu-yu-nei-rong-ti-qu.html
https://poi.apache.org/index.html
浙公网安备 33010602011771号