Last active
March 17, 2024 02:47
Convert Word Doc to XPS with NET REST API. https://kb.aspose.cloud/words/net/convert-doc-to-xps-with-net-rest-api/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aspose.Words.Cloud.Sdk; | |
using Aspose.Words.Cloud.Sdk.Model.Requests; | |
using System; | |
using System.IO; | |
namespace WordsSample.Words | |
{ | |
public class WordsToXps | |
{ | |
public void ConvertWordToXpsAsync() | |
{ | |
try | |
{ | |
var apiClient = new Configuration(); | |
apiClient.ClientSecret = "Client Secret"; | |
apiClient.ClientId = "Client Id"; | |
//Create the Words SDK object | |
WordsApi wordsConvertApi = new WordsApi(apiClient); | |
string inputFile = "Test1.docx"; | |
string outputXpsFile = "DOCXToXps"; | |
string outputFormat = "xps"; | |
//Read source file to bytes array | |
var inpuFileStream = File.Open(inputFile, FileMode.Open); | |
inpuFileStream.Position = 0; | |
ConvertDocumentRequest convertDocumentRequest = new ConvertDocumentRequest(inpuFileStream, outputFormat, null, null, null, null, null, null, null); | |
var conversionTask = wordsConvertApi.ConvertDocument(convertDocumentRequest); | |
conversionTask.Wait(); | |
var outputXpsFileStream = conversionTask.Result; | |
outputXpsFileStream.Position = 0; | |
using (var fileStream = File.Create(outputXpsFile+"."+ outputFormat)) | |
{ | |
outputXpsFileStream.Seek(0, SeekOrigin.Begin); | |
outputXpsFileStream.CopyTo(fileStream); | |
} | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment