android - 如何通过在android中将文本转换为pdf和pdf到docx来将文本转换为docx
问题描述
我想在 android 应用程序中将文本转换为 docx 格式。我想知道如何实现这一点。
我先尝试直接从文本转换为 docx。我尝试实现 Apache POI 和 Aspose 库,但没有找到我的解决方案。运行时的 Aspose 库给出了“重复 API”的错误,我检查了 Aspose 论坛它还没有解决。我尝试了它被告知的任何内容。
我尝试将文本实现为pdf,它完成了。现在我想知道如何从pdf转换为docx?
任何人都可以帮助提供适当的功能细节来完成这项任务吗?或任何其他建议,以便可以将文本转换为 docx?
// Below code is for converting directly from text to docx .
// This is using Apache POI but it is not importing classes after adding library
private void docxFormat()
{
XWPFDocument xwpfDocument = new XWPFDocument();
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(new File("yourfilepath/filename.docx"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
for(String s:lines) {
XWPFParagraph xwpfParagraph = xwpfDocument.createParagraph();
XWPFRun xwpfRun = xwpfParagraph.createRun();
xwpfRun.setText(s);
}
xwpfDocument.write(fileOutputStream);
fileOutputStream.close();
}
// Anybody any suggestion for converting text to docx
解决方案
您可以通过 Java API 的代码使用以下Aspose.Words for Android轻松地将文本文件转换为 Word 格式,例如 DOC、DOCX、RTF 和许多其他格式(PDF、XPS、HTML 等) :
try
{
String licString = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Aspose.Words.Android.lic";
String inputPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/input.txt";
String outputPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/output.docx";
com.aspose.words.License lic = new com.aspose.words.License();
lic.setLicense(licString, this);
com.aspose.words.Document doc = new com.aspose.words.Document(inputPath);
doc.save(outputPath);
}
catch (Exception e)
{
e.printStackTrace();
}
希望这可以帮助。我与 Aspose 一起担任开发人员宣传员。
推荐阅读
- recaptcha - 在 GUI 中显示来自 html-unit 的 reCaptcha
- php - 单个 WP_Query 可以从 X 标签获取帖子,但如果没有结果,则回退到 X 类别
- c++ - 什么时候可以安全地释放我传递给 DirectX 的内存?
- ios - 如何输出 iOS 发布二进制文件的函数列表
- r - iGraph for R 中的 stmincuts 问题
- amazon-eks - 如何更改每个节点的默认 Pod 数量?
- sonarqube - SonarQube Scannner 执行期间出错
- javascript - 角度 tslint 设置错误。ng build:成功,ng build --prod:失败
- xml - XSLT 1.0 Kludge 清理
- python-3.x - 如何通过套接字发送消息序列?