[英]How to Convert PDF file to DOC file in Android App Programmatic
我正在开发无需使用互联网即可将pdf
文件转换为word文件的android程序,请对此提供帮助。 我有一个解决方案,但抛出文件格式异常:
我搜索了许多开源库,但它无法帮助我
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.