Convert PDF to DOCX in C# MVC code using Aspose.Words REST API not returning the output download link

Hi, I am using c# .net to convert PDF to DOCX. I see the file is uploaded to aspose cloud.

However, how can I get the download link? The response doesn’t contain the output link. Here’s the code as per your GIT documentation. Seems not helping or I am failing somewhere. Please advice, since this is my first time using your component. Thanks.

            string fileName = file.FileName;
            string format = "docx";
            string destName = "Out_test_multi_pages.docx";

            // Upload original document to Cloud Storage
            wordsApi.UploadFile(new UploadFileRequest(file.InputStream, fname, null));

            SaveAsRequest request = new SaveAsRequest(fileName, new SaveOptionsData()
            {
                SaveFormat = format,
                FileName = destName
            }, null, null, null, null, null);
            SaveResponse result = wordsApi.SaveAs(request);

@jenkh

The SaveAs API method returns the output file path. You can use it to download the output file as follows. Hopefully, it will help you to accomplish the task.

If you do not want to use the storage, then you can convert the file from request content and get the output in response stream using ConvertDocument API method.

SaveResponse result = wordsApi.SaveAs(request);
Console.WriteLine(result.SaveResult.DestDocument.Href.ToString());

var requestDownload = new DownloadFileRequest(path: result.SaveResult.DestDocument.Href.ToString());
var actual = wordsApi.DownloadFile(requestDownload);
var fileStream = System.IO.File.Create("C:/Temp/"+ result.SaveResult.DestDocument.Href.ToString());
actual.CopyTo(fileStream);
fileStream.Close();
1 Like

Thank you very much. That works. Appreciate it.

1 Like