Created
February 17, 2026 11:55
-
-
Save aspose-com-gists/6084cd04357adb49a07ae9aa198a7a00 to your computer and use it in GitHub Desktop.
Python via .NET: Simple AI to PDF Conversion
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
| import sys | |
| from aspose.psd import Image, PdfExportOptions | |
| def convert_ai_to_pdf(input_path: str, output_path: str): | |
| """ | |
| Convert an AI file to PDF preserving vectors and layers. | |
| """ | |
| try: | |
| # Load the AI file | |
| ai_image = Image.load(input_path) | |
| # Configure PDF export options | |
| options = PdfExportOptions() | |
| options.embed_all_fonts = True # Ensure text remains selectable | |
| options.preserve_layers = True # Keep original layer structure | |
| options.pdf_version = "1.7" # Use PDF 1.7 for better compatibility | |
| # Save the image as PDF | |
| ai_image.save(output_path, options) | |
| print(f"Conversion successful: '{output_path}'") | |
| except Exception as e: | |
| print(f"Error during conversion: {e}", file=sys.stderr) | |
| finally: | |
| # Ensure resources are released | |
| if 'ai_image' in locals(): | |
| ai_image.dispose() | |
| if __name__ == "__main__": | |
| # Example usage | |
| convert_ai_to_pdf("sample.ai", "sample_converted.pdf") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment