简体   繁体   中英

How to convert text to docx by converting text to pdf and pdf to docx in android

I want to convert text to docx format in android app.I want to know how I could achieve the same.

I tried directly converting from text to docx first. I tried implementing Apache POI and Aspose library but I didn't find my solution. Aspose library on runtime gave error of "Duplicate API ", I checked Aspose forum it is not resolved yet.I tried whatever it is told.

I tried implementing text to pdf it is done. Now I want to know how to convert from pdf to docx?

Can anybody help with proper functioning details to achieve this task? or any other suggestion so that text to docx can be converted?

// 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

You can easily convert a Text file to Word formats such as DOC, DOCX, RTF and to many other formats (PDF, XPS, HTML etc) by using the following Aspose.Words for Android via Java API's code:

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();
}

Hope, this helps. I work with Aspose as Developer Evangelist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM