I am using the aspose Cloud but the jpg returned is a zero byte file. Can you help?
public static void Convert(string wordDocumentPath, string tempFolder)
{
// Set up the configuration for Aspose.Words Cloud SDK
var config = new Configuration
{
ClientId = "I am hiding it", // Replace with your App SID
ClientSecret = "I am hiding it" // Replace with your App Key
};
string inputFile = wordDocumentPath;
string format = "jpg";
try
{
// Ensure tempFolder exists, create it if not
if (!Directory.Exists(tempFolder))
{
Directory.CreateDirectory(tempFolder);
}
// Set the output path to the specified tempFolder
string resultant = Path.Combine(tempFolder, "converted.jpg");
var wordsApi = new WordsApi(config);
// Open the Word document as a stream
using (var inputStream = System.IO.File.OpenRead(inputFile))
{
// Create ConvertDocumentRequest object without outPath to get the result as a stream
var request = new ConvertDocumentRequest(inputStream, format: format);
// Trigger the Word to JPG conversion and capture the response
var responseStream = wordsApi.ConvertDocument(request);
if (responseStream != null)
{
// Save the response stream to a file
using (var fileStream = new FileStream(resultant, FileMode.Create, FileAccess.Write))
{
responseStream.CopyTo(fileStream);
}
// Check file size after saving
FileInfo fileInfo = new FileInfo(resultant);
Console.WriteLine($"Word to JPG conversion successful! Image saved to: {resultant}");
Console.WriteLine($"File size: {fileInfo.Length} bytes");
if (fileInfo.Length == 0)
{
Console.WriteLine("Error: The file was saved but is empty (0 bytes).");
}
}
else
{
Console.WriteLine("Error: Received an empty response stream from the conversion.");
}
}
}
catch (ApiException apiEx)
{
Console.WriteLine($"API Error: {apiEx.Message}\n{apiEx.StackTrace}");
}
catch (Exception ex)
{
Console.WriteLine("General Error: " + ex.Message + "\n" + ex.StackTrace);
}
}