Last active
March 17, 2024 02:40
Convert DOC to PDF with NET REST API.https://kb.aspose.cloud/words/net/convert-doc-to-pdf-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 DocToPdf | |
{ | |
public void ConvertDocToPdfAsync() | |
{ | |
try | |
{ | |
var apiClient = new Configuration(); | |
apiClient.ClientSecret = "Secret"; | |
apiClient.ClientId = "ID"; | |
//Create SDK object | |
WordsApi wordsApi = new WordsApi(apiClient); | |
string input = "Test1.doc"; | |
string output = "DOCToPDF"; | |
string format = "pdf"; | |
//Read input file to bytes array | |
var fileStream = File.Open(input, FileMode.Open); | |
fileStream.Position = 0; | |
ConvertDocumentRequest docToPdfRequest = new ConvertDocumentRequest(fileStream, format, null, null, null, null, null, null, null); | |
var task = wordsApi.ConvertDocument(docToPdfRequest); | |
task.Wait(); | |
var outputFileStream = task.Result; | |
outputFileStream.Position = 0; | |
using (var stream = File.Create(output+"."+ format)) | |
{ | |
outputFileStream.Seek(0, SeekOrigin.Begin); | |
outputFileStream.CopyTo(stream); | |
} | |
} | |
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