如何通过在android中将文本转换为pdf和pdf转换为docx将文本转换为docx

z18hc3ub  于 2023-05-12  发布在  Android
关注(0)|答案(1)|浏览(260)

我想在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
kr98yfug

kr98yfug1#

您可以使用以下Aspose.Words for Android via Java API代码轻松地将文本文件转换为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合作,担任开发者布道者。

相关问题