作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发 Android,可以在不使用互联网的情况下将 pdf
文件转换为 Word 文件,有人可以帮助我吗?我有一个解决方案,但抛出文件格式异常:
我搜索了很多开源库,但它不能帮助我
Document pdfDocument = new Document(new File(selectedImagePath).getAbsolutePath());
String path = new File(Environment.getExternalStorageDirectory().getAbsolutePath()) + "/Test.doc";
pdfDocument.save(path, SaveFormat.Doc);
错误:
class com.aspose.pdf.internal.ms.System.ArgumentException: Save a document to a doc format is not supported.
最佳答案
尝试下面的代码
static String pdftoText(String fileName) {
PDFParser parser;
String parsedText = null;
PDFTextStripper pdfStripper = null;
PDDocument pdDoc = null;
COSDocument cosDoc = null;
File file = new File(fileName);
if (!file.isFile()) {
System.err.println("File " + fileName + " does not exist.");
return null;
}
try {
parser = new PDFParser(new FileInputStream(file));
} catch (IOException e) {
System.err.println("Unable to open PDF Parser. " + e.getMessage());
return null;
}
try {
parser.parse();
cosDoc = parser.getDocument();
pdfStripper = new PDFTextStripper();
pdDoc = new PDDocument(cosDoc);
parsedText = pdfStripper.getText(pdDoc);
} catch (Exception e) {
System.err
.println("An exception occured in parsing the PDF Document."
+ e.getMessage());
} finally {
try {
if (cosDoc != null)
cosDoc.close();
if (pdDoc != null)
pdDoc.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return parsedText;
}
关于java - 如何在 Android 应用程序中将 PDF 文件转换为 DOC 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56169282/
我是一名优秀的程序员,十分优秀!