Created
December 17, 2025 07:31
-
-
Save GroupDocsGists/448aa05133d3ce0763ec98d4085b7dd5 to your computer and use it in GitHub Desktop.
Convert SVG to JPG with GroupDocs.Conversion for .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 GroupDocs.Conversion; | |
| using GroupDocs.Conversion.Options.Convert; | |
| using System.Drawing; | |
| namespace SvgToJpgDemo | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| // Path to the source SVG file | |
| string sourcePath = "sample.svg"; | |
| // Path for the output JPG file | |
| string outputPath = "sample_converted.jpg"; | |
| // Optional: specify a license file for production use | |
| var config = new ConversionConfig | |
| { | |
| LicensePath = "GroupDocs.Total.NET.lic" // Remove or comment out for trial mode | |
| }; | |
| try | |
| { | |
| // Initialize the converter with the SVG source | |
| using var converter = new Converter(sourcePath, config); | |
| // Configure JPG conversion options | |
| var jpgOptions = new JpgConvertOptions | |
| { | |
| Quality = 90, // JPEG quality (0-100) | |
| Width = 1024, // Desired width in pixels | |
| Height = 768, // Desired height in pixels | |
| BackgroundColor = Color.White // Background for transparent SVGs | |
| }; | |
| // Perform the conversion | |
| converter.Convert(outputPath, jpgOptions); | |
| Console.WriteLine($"Conversion successful. JPG saved to: {outputPath}"); | |
| } | |
| catch (Exception ex) | |
| { | |
| Console.WriteLine($"Error during conversion: {ex.Message}"); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment