Generating preview images from tabular data is a common requirement when building dashboards or email reports. GroupDocs.Conversion Cloud SDK for Node.js provides a powerful API that can transform CSV files into high‑quality JPG images on the server side. You will learn how to convert CSV to JPG in Node.JS using the library’s async methods, see a complete code example, explore equivalent cURL calls, and discover configuration options for fine‑tuning the output.
Convert CSV to JPG in Node.JS - Complete Code Example
This example demonstrates how to convert a CSV file stored in GroupDocs Cloud storage into JPG images using the library’s async API.
const { ConvertApi, ConvertSettings, ConvertOptions, FileInfo } = require("@groupdocs/conversion-cloud");
// Replace with your actual GroupDocs Cloud credentials
const clientId = "YOUR_CLIENT_ID";
const clientSecret = "YOUR_CLIENT_SECRET";
async function convertCsvToJpg() {
// Initialize the Conversion API
const convertApi = new ConvertApi(clientId, clientSecret);
// Source CSV file stored in GroupDocs Cloud storage
const fileInfo = new FileInfo();
fileInfo.filePath = "input.csv";
// Conversion options: CSV -> JPG
const convertOptions = new ConvertOptions();
convertOptions.fileInfo = fileInfo;
convertOptions.format = "jpg";
// Conversion settings (output folder in storage)
const convertSettings = new ConvertSettings();
convertSettings.outputPath = "output_images";
convertSettings.convertOptions = [convertOptions];
try {
const result = await convertApi.convertDocument(convertSettings);
console.log("Conversion completed. Generated files:");
result.forEach(file => console.log(file.path));
} catch (err) {
console.error("Conversion failed:", err);
}
}
convertCsvToJpg();
Note: This code example demonstrates the core functionality. Before using it in your project, make sure to update the file paths (
input.csv,output_images, etc.) to match your actual file locations, verify that all required dependencies are properly installed, and test thoroughly in your development environment. If you encounter any issues, please refer to the official documentation or reach out to the support team for assistance.
CSV to JPG Conversion Using cURL and REST API
If you prefer a pure REST approach, the same conversion can be performed with a series of cURL commands.
- Obtain an access token - authenticate with your client credentials.
curl -X POST "https://api.groupdocs.cloud/v2.0/auth/token" \
-H "Content-Type: application/json" \
-d '{"client_id":"YOUR_CLIENT_ID","client_secret":"YOUR_CLIENT_SECRET"}'
- Upload the source CSV - place the file in your GroupDocs Cloud storage.
curl -X POST "https://api.groupdocs.cloud/v2.0/storage/upload?path=input.csv" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-F "file=@/path/to/your/input.csv"
- Request the conversion - specify the target format as JPG.
curl -X POST "https://api.groupdocs.cloud/v2.0/conversion/convert?format=jpg" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"fileInfo":{"filePath":"input.csv"}}'
- Download the generated image(s) - retrieve the files from the output folder.
curl -X GET "https://api.groupdocs.cloud/v2.0/storage/download?path=output_images/your_image.jpg" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-o your_image.jpg
These commands illustrate a complete CSV‑to‑JPG workflow without writing any code. For more details, see the official API documentation.
Understanding the CSV to JPG Process in Node.JS
Below is a step‑by‑step breakdown of the code shown earlier:
Initialize the API client -
new ConvertApi(clientId, clientSecret)creates an authenticated session.const convertApi = new ConvertApi(clientId, clientSecret);Define the source file - a
FileInfoobject points toinput.csvstored in GroupDocs Cloud.const fileInfo = new FileInfo(); fileInfo.filePath = "input.csv";Set conversion options -
ConvertOptions.format = "jpg"tells the service to produce JPG output.const convertOptions = new ConvertOptions(); convertOptions.fileInfo = fileInfo; convertOptions.format = "jpg";Configure output settings -
ConvertSettings.outputPathdetermines where the images will be saved.const convertSettings = new ConvertSettings(); convertSettings.outputPath = "output_images"; convertSettings.convertOptions = [convertOptions];Execute the conversion -
convertApi.convertDocument(convertSettings)sends the request and returns an array of generated file paths.const result = await convertApi.convertDocument(convertSettings);
For a full list of classes and properties, refer to the API reference.
Prerequisites and Setup
- Node.js runtime - version 12 or higher is required.
- GroupDocs Cloud account - obtain
clientIdandclientSecretfrom the GroupDocs portal. - Install the SDK - run the following command (download package from the official release page):
npm install groupdocs-conversion-cloud
- Import the SDK in your project:
const { ConvertApi, ConvertSettings, ConvertOptions, FileInfo } = require("@groupdocs/conversion-cloud");
For more details on installation, see the download page.
Conversion Settings: Options and Parameters
The SDK exposes several properties you can tweak:
Output Path - controls the folder where JPG files are stored.
convertSettings.outputPath = "output_images";Target Format - change
"jpg"to"jpeg"if you need the JPEG variant.convertOptions.format = "jpeg";Custom Dimensions - you can specify width and height (if supported) to generate images with exact size.
convertOptions.width = 800; // example width in pixels convertOptions.height = 600; // example height in pixelsAsynchronous Execution - the SDK methods return promises, allowing you to integrate the conversion into async workflows without blocking the event loop.
await convertApi.convertDocument(convertSettings);
These options let you tailor the CSV‑to‑JPG workflow to fit your specific automation or integration needs.
Conclusion
Converting CSV to JPG in Node.JS is straightforward with the GroupDocs.Conversion Cloud SDK for Node.js. The library handles the heavy lifting in the cloud, letting you focus on business logic and integration. Remember to secure your Cloud credentials, choose the appropriate output format (JPG or JPEG), and adjust settings such as dimensions or output paths to match your workflow. For production deployments you’ll need a paid license; you can explore pricing details and obtain a temporary license from the temporary license page. With the code and cURL examples provided, you’re ready to add CSV‑to‑JPG automation to any backend service.
FAQs
How do I convert CSV to JPG in Node.JS without writing custom parsing logic?
The SDK reads the CSV directly from GroupDocs Cloud storage and renders each row as an image, so you don’t need any external tools. Just follow the code example or the cURL workflow.Is it possible to convert CSV to JPEG instead of JPG in the backend?
Yes. SetconvertOptions.format = "jpeg"in the code or useformat=jpegin the REST request. Both formats are supported for backend conversion in Node.JS.Can I run the conversion asynchronously to avoid blocking my server?
Absolutely. All SDK methods return promises, so you canawaitthem or attach.then()handlers. This enables non‑blocking, scalable CSV‑to‑JPG automation.Where can I find more examples of CSV to image conversions?
The official documentation contains additional samples, and the community forum at GroupDocs Conversion Forum is a good place to ask questions.
