Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save conholdate-gists/65bf9e2c10c7886017fba821ad622e36 to your computer and use it in GitHub Desktop.

Select an option

Save conholdate-gists/65bf9e2c10c7886017fba821ad622e36 to your computer and use it in GitHub Desktop.
How to Convert CDR to PNG using API in .NET
using System;
using Conholdate.Total;
using Conholdate.Total.Conversion;
using System.Drawing;
namespace CdrToPngDemo
{
class Program
{
static void Main(string[] args)
{
// Validate input arguments
if (args.Length < 2)
{
Console.WriteLine("Usage: CdrToPngDemo <input.cdr> <output_folder>");
return;
}
string inputPath = args[0];
string outputFolder = args[1];
try
{
// Initialize the conversion engine
var converter = new Conversion();
// Load the CDR document
var loadOptions = new LoadOptions { Format = FileFormat.Cdr };
var document = converter.Load(inputPath, loadOptions);
// Set PNG export options
var pngOptions = new PngOptions
{
Resolution = 300,
CompressionLevel = 6,
BackgroundColor = Color.White
};
// Ensure output folder exists
System.IO.Directory.CreateDirectory(outputFolder);
// Convert each page to a separate PNG file
for (int pageIndex = 0; pageIndex < document.PageCount; pageIndex++)
{
string outputPath = System.IO.Path.Combine(outputFolder, $"page_{pageIndex + 1}.png");
converter.Save(document, outputPath, pngOptions, pageIndex);
Console.WriteLine($"Saved page {pageIndex + 1} to {outputPath}");
}
Console.WriteLine("Conversion completed successfully.");
}
catch (Exception ex)
{
Console.Error.WriteLine($"Error during conversion: {ex.Message}");
// For detailed troubleshooting, enable logging as described in the docs
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment