
CSV to JPG Converter in C# .NET.
Converting CSV (Comma-Separated Values) files to JPEG (Joint Photographic Experts Group) images using C# .NET offers a myriad of benefits that are indispensable in today’s data-centric environment. This transformation not only allows the creation of visually engaging charts, graphs, and diagrams but also plays a crucial role in data visualization and communication. Though the image to CSV conversion is important, but for now, our focus is on the crucial CSV to JPG transformation for enhanced data visualization using REST API.
- REST API for CSV to JPG Conversion
- Comma Delimited Values File to JPG in C# .NET
- Convert CSV to JPG using cURL Commands
REST API for CSV to JPG Conversion
GroupDocs.Conversion Cloud SDK for .NET offers a robust solution for converting CSV files to JPG images with unmatched efficiency and quality. Therefore, by leveraging the power of cloud-based processing, this SDK ensures seamless and accurate conversion, preserving data integrity and visual fidelity. Let’s explore the details on how we can unlock the full potential of our data by transforming tabular information into impactful visual representations for enhanced data analysis, reporting, and presentation.
The first step is to install the SDK by searching GroupDocs.Conversion-Cloud in NuGet package manager and click the Install button. Another option is to execute the following command in package manager console.
NuGet\Install-Package GroupDocs.Conversion-Cloud -Version 24.4.0
The next important step is to obtain the personalized API credentials(i.e. Client ID and Client Secret). Please follow the instructions specified in this short tutorial explaining the details on how to get the API credentials.
Comma Delimited Values File to JPG in C# .NET
This section explains how this API simplifies the conversion process, allowing you to seamlessly integrate CSV to JPG conversion functionality into your .NET applications.
- Create an instance of
Configuration
class where we pass client credentials as arguments.
var configurations = new Configuration(clientId, clientSecret1);
- Initialize the
ConvertApi
where we pass Configuration object as an input argument.
var apiInstance = new ConvertApi(configurations);
- Upload the input CSV file to the cloud storage.
fileUpload.UploadFile(new UploadFileRequest("input.csv", stream));
- Create an instance
ConvertSettings
where we specify the name for input CSV, resultant format asjpg
and the name for output JPG image as arguments.
var settings = new ConvertSettings{...}
- Call the ConvertDocumentRequest API to convert CSV to JPG and save the resultant JPEG image to the cloud storage.
var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings));
// 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 !"); | |
} | |
} |
Convert CSV to JPG without Uploading to Cloud Storage
In case do not want to upload the input CSV to cloud storage and want to convert the inline CSV to JPG image, please try using following code snippet.
// 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(); | |
} |
Image:- A preview of CSV to JPG image conversion.
The input CSV file and the resultant JPG image can be downloaded from input.csv and myResultant.jpg.
Convert CSV to JPG using cURL Commands
Converting CSV files to JPG images using GroupDocs.Conversion Cloud is a streamlined process facilitated by cURL commands. With a simple POST request to the API endpoint and specifying the input CSV file along with the desired output format as JPG, you can initiate the conversion effortlessly.
The first step is to generate a JWT access token based on client credentials and once we have generated the JWT token, please execute the following cURL command to convert CSV to JPG image and save the resultant JPG file in cloud storage.
curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{ \"StorageName\": \"internal\", \"FilePath\": \"{sourceFile}\", \"Format\": \"jpg\", \"LoadOptions\": { \"Format\": \"csv\" },\"OutputPath\": \"{myResultantFile}\"}"
Please replace sourceFile
with the name of input CSV file, myResultantFile
with the name of resultant JPG image and accessToken
with personalized JWT access token.
- Now, if we need to save the resultant JPG on local drive, please try using the following cURL command:
curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{ \"StorageName\": \"internal\", \"FilePath\": \"{sourceFile}\", \"Format\": \"jpg\", \"LoadOptions\": { \"Format\": \"csv\" }}" \
-o "myResultantFile.jpg"
Free CSV to HTML Converter
We highly recommend using our lightweight and supper-efficient CSV to JPEG Converter app built on top of GroupDocs.Conversion Cloud REST APIs as it enables you to witness the amazing capabilities of CSV to JPEG conversion API.
Useful Links
Conclusion
Whether you prefer the simplicity of cURL commands or the flexibility of integrating directly with our API, GroupDocs.Conversion Cloud offers a comprehensive solution for converting CSV files to JPG images. So, with the help of this API, unlock the potential for enhanced data visualization, reporting, and presentation by transforming your data into compelling visual narratives today.
Related Articles
We highly recommend visiting the following links to learn more about: