Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code snippets for converting Word document to JPG using C#
// get client credentials from https://dashboard.aspose.cloud/
string clientSecret = "caac6e3d4a4724b2feb53f4e460eade3";
string clientID = "4ccf1790-accc-41e9-8d18-a78dbb2ed1aa";
// create Configuration instnace by passing Client ID and Client secret details
var config = new Configuration { ClientId = clientID, ClientSecret = clientSecret };
// create WordsApi object
var wordsApi = new WordsApi(config);
// input Word file name
string fileName = "sample1.docx";
// resultant file name
string outputfile = "converted.jpeg";
try
{
// Create request object by passing input DOCX path, output format and resultant file name
ConvertDocumentRequest request = new ConvertDocumentRequest(System.IO.File.OpenRead("/Users/nshahbaz/Downloads/" + fileName), "jpeg", outputfile);
// perform DOCX conversion to JPG
wordsApi.ConvertDocument(request);
}
catch (Exception ex)
{
Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
Code snippets for converting Word document to JPG using Aspose.Words Cloud SDK for .NET.
// get client credentials from https://dashboard.aspose.cloud/
string clientSecret = "caac6e3d4a4724b2feb53f4e460eade3";
string clientID = "4ccf1790-accc-41e9-8d18-a78dbb2ed1aa";
// create Configuration instnace by passing Client ID and Client secret details
var config = new Configuration { ClientId = clientID, ClientSecret = clientSecret };
// create WordsApi object
var wordsApi = new WordsApi(config);
// name of input Word document
string fileName = "sample1.docx";
// required output format
string format = "jpg";
// resultant file name
string outputfile = "converted.jpg";
// load the content of word file
using (var file = System.IO.File.OpenRead("/Users/nshahbaz/Downloads/" + fileName))
{
// Upload original document to Cloud Storage
wordsApi.UploadFile(new UploadFileRequest(file, fileName, null));
}
try
{
// create request object with input word file, output format and resultant file name as arguments
GetDocumentWithFormatRequest request = new GetDocumentWithFormatRequest(fileName,format,null,null,null,null,outputfile);
// initialize the conversion process
wordsApi.GetDocumentWithFormat(request);
}
catch (Exception ex)
{
Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment