Created
March 10, 2026 23:56
-
-
Save conholdate-gists/65bf9e2c10c7886017fba821ad622e36 to your computer and use it in GitHub Desktop.
How to Convert CDR to PNG using API in .NET
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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