@dev1sheeta
You can convert DOCX to PDF using Aspose.Words Cloud SDK for .NET. First thing first, sign up with aspose.cloud and get the credentials. Either you can convert files from cloud storage or from the request body(streams). Please check the following sample code for details.
Convert Documents from Cloud Storage:
[GET /words/{name}(https://apireference.aspose.cloud/words/#/Convert/GetDocumentWithFormat) Converts a document in cloud storage to the specified format
C# code:
// Get Client Id and Client Secret from https://dashboard.aspose.cloud/
WordsApi wordsApi = new WordsApi(ClientId, ClientSecret);
string localFolder = "C:/Temp/";
string remoteFolder = "Temp";
string localName = "02_pages.docx";
string remoteName = "02_pages.docx";
string outPutName = "02_pages.pdf";
Aspose.Words.Cloud.Sdk.Model.Requests.UploadFileRequest uploadRequest = new Aspose.Words.Cloud.Sdk.Model.Requests.UploadFileRequest(System.IO.File.OpenRead(localFolder + localName), remoteFolder + "/" + remoteName);
wordsApi.UploadFile(uploadRequest);
var convertRequest = new GetDocumentWithFormatRequest(
name: remoteName,
format: "pdf",
folder: remoteFolder,
outPath: outPutName
);
var convertResponse = wordsApi.GetDocumentWithFormat(convertRequest);
var requestDownload = new Aspose.Words.Cloud.Sdk.Model.Requests.DownloadFileRequest(path: remoteFolder+"/"+outPutName);
var downloadResponse = wordsApi.DownloadFile(requestDownload);
var fileStream = System.IO.File.Create("C:/Temp/02_pages_out.pdf");
downloadResponse.CopyTo(fileStream);
fileStream.Close();
Convert Documents without Cloud Storage:
PUT /words/convert Converts a document on a local drive to the specified format
C# code:
// Get Client Id and Client Secret from https://dashboard.aspose.cloud/
WordsApi wordsApi = new WordsApi(ClientId, ClientSecret);
var request = new ConvertDocumentRequest(
document: File.OpenRead("C:/Temp/Test.docx"),
format: "pdf"
);
var result = wordsApi.ConvertDocument(request);
var fileStream = System.IO.File.Create("C:/Temp/Test.pdf");
result.CopyTo(fileStream);
fileStream.Close();
You can download the Aspose.Words Cloud SDK for .NET from GitHub or NuGet. And secondly please note we have used default internal storage(Aspose) so did not pass the cloud storage name in the API call explicitly. If you want to use one of the other supported Cloud storages then you need to pass the storage name in the API request as well.