[英]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.