Skip to content

Instantly share code, notes, and snippets.

@groupdocs-cloud-gists
Last active May 8, 2024 00:31
Show Gist options
  • Save groupdocs-cloud-gists/4f3b907a69061ca1f63ba363465247e8 to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/4f3b907a69061ca1f63ba363465247e8 to your computer and use it in GitHub Desktop.
CSV to JPG converter

Perform CSV to JPG Conversion C# .NET


The conversion of CSV files to JPEG images using C# .NET bridges the gap between data analysis and visualization, enabling you to create compelling graphics from tabular data. This article explains the details for converting CSV to JPG image online using GroupDocs.Conversion Cloud SDK for .NET.



For more details, please visit Convert CSV to JPEG using C# .NET.

csv to jpg

Important Links

Product Page | Docs | Live Demo | API Reference | Code Samples | Source Code | New Releases | Blog | Free Support | Free Trial

How to convert CSV to JPG with C# .NET
// More examples over https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-dotnet
// Obtain your API credentials
string clientId = "4bdefca3-f08c-4088-9ca0-55c38f4b7f22";
string clientSecret1 = "a43c8b4365246a062688a259abe5b469";
// Create an instance of the Configuration class and initialize it with the Client ID & Client Secret.
var configurations = new GroupDocs.Conversion.Cloud.Sdk.Client.Configuration(clientId, clientSecret1);
// Define the value of ApiBaseUrl to set the base url of CSV to JPG conversion API.
configuration.ApiBaseUrl = "https://api.groupdocs.cloud";
// Initialize an instance of the ConvertApi class with the object of the Configuration class.
var apiInstance = new GroupDocs.Conversion.Cloud.Sdk.Api.ConvertApi(configurations);
// read the content of input Comma Separated Values file from local drive
using (var stream = System.IO.File.OpenRead("source.csv"))
{
// Invoke the ConvertDocument method to convert CSV to JPG programmatically.
var response = apiInstance.ConvertDocumentDirect(new ConvertDocumentDirectRequest("jpg", stream, fromPage: 1, pagesCount: 1));
if (response != null && response.Equals("OK"))
{
// print success message
Console.WriteLine("The CSV to JPG image conversion completed successfully !");
}
// our custom method to save resultant JPG on local drive
saveToDisk(response, @"D:\myConverted.jpg");
}
// Our custom method to save stream content to file on local drive
public static void saveToDisk(Stream responseStream, String resultantFile)
{
var fileStream = File.Create(resultantFile);
responseStream.Seek(0, SeekOrigin.Begin);
responseStream.CopyTo(fileStream);
fileStream.Close();
}
// More examples over https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-dotnet
// Obtain your API credentials
string clientId = "4bdefca3-f08c-4088-9ca0-55c38f4b7f22";
string clientSecret1 = "a43c8b4365246a062688a259abe5b469";
// Create an instance of the Configuration class and initialize it with the Client ID & Client Secret.
var configurations = new GroupDocs.Conversion.Cloud.Sdk.Client.Configuration(clientId, clientSecret1);
// Define the value of ApiBaseUrl to set the base url of CSV to JPG conversion API.
configuration.ApiBaseUrl = "https://api.groupdocs.cloud";
// Initialize an instance of the ConvertApi class with the object of the Configuration class.
var apiInstance = new GroupDocs.Conversion.Cloud.Sdk.Api.ConvertApi(configurations);
// read the content of input Comma Separated Values file from local drive
using (var stream = System.IO.File.OpenRead("source.csv"))
{
// create an instance of FileApi
var fileUpload = new FileApi(configurations);
// upload the input CSV to cloud storage
fileUpload.UploadFile(new UploadFileRequest("input.cs", stream));
// create ConvertSettings where we define the input CSV file name and the resultant JPG image
var settings = new ConvertSettings
{
StorageName = "internal",
FilePath = "input.cs",
Format = "jpg",
OutputPath = "myResultant.jpg"
};
// Invoke the ConvertDocument method for CSV to JPG conversion.
var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings));
if (response != null && response.Equals("OK"))
{
// print success message
Console.WriteLine("The CSV to JPG image conversion completed successfully !");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment