Skip to content

Instantly share code, notes, and snippets.

@groupdocs-cloud-gists
Last active August 26, 2024 18:32
Show Gist options
  • Save groupdocs-cloud-gists/2e52ea1598c995e9d748f9429886b4ca to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/2e52ea1598c995e9d748f9429886b4ca to your computer and use it in GitHub Desktop.
Convert JPG to Word
How to Convert Photo to Word document
// More examples over https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-dotnet
// Obtain your API credentials
string clientId = "XXXXXX-XXXXXXXXX-4088-9ca0-55c38f4b7f22";
string clientSecret1 = "XXXXXXXXXXXXXXXXXXXX";
// Create an instance of the Configuration class and initialize it with the Client ID & Client Secret.
var configurations = new Configuration(clientId, clientSecret1);
// Define the value of ApiBaseUrl to set the base url for JPG to DOC conversion API.
configuration.ApiBaseUrl = "https://api.groupdocs.cloud";
// Initialize an instance of the ConvertApi class with an object of Configuration class.
var apiInstance = new ConvertApi(configurations);
// load the input JPG photo from local drive
using (var stream = System.IO.File.OpenRead("sample.jpg"))
{
// create an instance of FileApi
var fileUpload = new FileApi(configurations);
// upload the input MPP to cloud storage
fileUpload.UploadFile(new UploadFileRequest("sample.jpg", stream));
// create ConvertSettings where we specify the name of input JPG image and the name for resultant Word document
var settings = new ConvertSettings
{
StorageName = "default",
FilePath = "sample.jpg",
Format = "doc",
OutputPath = "resultant.doc"
};
// Invoke the ConvertDocument method for JGP to DOC conversion operation.
var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings));
if (response != null && response.Equals("OK"))
{
// print success message
Console.WriteLine("JPG to Word document conversion completed successfully !");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment