Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/7c6acf3a4f0f5f99fc0b6df7a389c086 to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/7c6acf3a4f0f5f99fc0b6df7a389c086 to your computer and use it in GitHub Desktop.
How to Convert AI Files to SVG in Python via .NET
import sys
from aspose.psd import Image
from aspose.psd.imageoptions import SvgExportOptions
def convert_ai_to_svg(input_path: str, output_path: str):
"""
Converts an AI file to SVG format.
Parameters:
input_path – Path to the source .ai file.
output_path – Desired path for the resulting .svg file.
"""
try:
# Load the AI file
ai_image = Image.load(input_path)
# Set up SVG export options
svg_options = SvgExportOptions()
svg_options.vectorize_text = True # Convert text to vector paths
svg_options.embed_fonts = True # Keep fonts embedded
svg_options.image_quality = 100 # Preserve bitmap layer quality
# Save as SVG
ai_image.save(output_path, svg_options)
print(f"Successfully converted '{input_path}' to '{output_path}'.")
except Exception as ex:
print(f"Error during conversion: {ex}", file=sys.stderr)
raise
finally:
# Ensure native resources are released
if 'ai_image' in locals():
ai_image.dispose()
if __name__ == "__main__":
# Example usage
convert_ai_to_svg("example.ai", "example.svg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment