How to convert PDF to Microsoft Word Document in Android with Aspose.Words REST API

I try build project example GitHub - aspose-words-cloud/aspose-words-cloud-java: A Java library for communicating with the Aspose.Words Cloud API (I changed AppKey and AppSid).
When press button convert pick file PDF:
java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.String com.google.gson.JsonElement.toString()’ on a null object reference.

Help me !

Hi all,
I try build project example GitHub - aspose-words-cloud/aspose-words-cloud-java: A Java library for communicating with the Aspose.Words Cloud API (I changed AppId & ApiKey).
When press button convert:
java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.String com.google.gson.JsonElement.toString()’ on a null object reference
W/System.err: at com.aspose.words.cloud.ApiClient.handleResponse(ApiClient.java:877)
at com.aspose.words.cloud.ApiClient.execute(ApiClient.java:787)
at com.aspose.words.cloud.api.WordsApi.convertDocumentWithHttpInfo(WordsApi.java:860)
at com.aspose.words.cloud.api.WordsApi.convertDocument(WordsApi.java:837)
W/System.err: at com.example.asposewordscloudandroid.MainActivity$onActivityResult$1.run(MainActivity.kt:131)

Thank and best regards !

@phuongkna79

Thanks for your inquiry. It seems servercreds.json file is missing in asset folder. Please find sample servercreds.jsonservercreds.zip (211 Bytes) file, update your aspose.cloud credentials in it and save to asset folder of the project. It will fix your above reported issue.

@phuongkna79

We are sorry for your inconvenience. I’m looking into the issue and will update you with a sample code soon.

Thank you for comment, i need project android example for demo feature convert file pdf to file word,
I hope it will be soon.

Thank and best regards !

@phuongkna79
Please find sample Android Project to convert PDF document to DOCX.

https://drive.google.com/open?id=1HZUaFHBFvwbw4Gkesin-6E1Owedm8d39

You may check complete units tests of Aspose.Words Cloud API from github repo as well.

Hi tilal.ahmad,

 //Convert PDF to DOCX from cloud storage https://apireference.aspose.cloud/words/#/Convert/SaveAs
            String fileName = "02_pages.pdf";
            String destName= "02_pages.docx";
            SaveOptionsData saveOptionsData = new 
            SaveOptionsData().saveFormat("docx").fileName(destName);
            // wordsApi.uploadFile(new UploadFileRequest(new File(file),fileName,null));
            SaveAsRequest request = new SaveAsRequest(fileName, saveOptionsData,null,
                    null, null, null, null);
            SaveResponse result = wordsApi.saveAs(request);
            //Save stream result to storage
            //FilesUploadResult result = imagingApi.uploadFile(new UploadFileRequest("Watermark_out.pdf", exportedImage, storage)); 

How to save stream result to storage (file docx to storage)??

Thank and best regards !

@phuongkna79

Thanks for your inquiry. Can you please share more details about your requirement? Because, PDF to DOC/DOCX conversion API already saving resultant DOC/DOCX file to storage.

I want convert file pdf to word, when run api convert i not found file docx in device.

Have i implemented correctly?
Example: file Kna.pdf convert >> Kna.docx (not found).
Screen Shot 2020-03-18 at 9.36.15 PM.png (320.6 KB)

Thank and best regards !

@phuongkna79

It seems fine. However, please note SaveAs API method saves the result file to Cloud Storage. As we are passing a null parameter for storage so DOCX file is being saved to Aspose Cloud default storage. If you want to download the DOCX file to device storage then please use DownloadFile Method for the purpose.

DownloadFileRequest downloadRequest = new DownloadFileRequest(destName, null, null);
File outputFile = wordsApi.downloadFile(downloadRequest);
File dest = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+destName);
Files.copy(outputFile.toPath(), dest.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);