Parse Adobe Illustrator (.ai) files with Python
Asked Answered
D

2

7

I'm using Python under Linux. Could you please recommend some libs or command line tools to parse Adobe Illustrator (.ai) files which I can use in my Python program?

What I need to do includes:

  1. Convert .ai files to .jpeg or .png images
  2. Extract text from .ai files
  3. Read .ai files information (e.g. version number, something like psdparse for AI)

I need it under Ubuntu so I cannot use win32com

Donn answered 21/11, 2011 at 7:24 Comment(1)
Answer #1) Try imagemagick.org which has support for Python. May be easier to use command line convert*. Unsure on question #2 or #3.Sodom
A
6

I think many modern .AI files are just extended PDF files. A quick test would be: rename the .AI to .PDF and see if your PDF reader can open it. If so, there are plenty of tools to deal with PDF files.

If you have older .AI files then you can try Uniconvertor. It is Python, perhaps you can import some functionality from it.

[update]

This answer is quite old. If it does not work for you leave a comment with what went wrong.

Almeta answered 13/1, 2012 at 22:46 Comment(3)
Uniconvertor will work only for Adobe Illustrator up to version 9 (AI postscript based). After that AI is PDF based.Applesauce
New ones are PS as far as I understood. Thanks for help!Cappello
New one using EPS, which is different than PS. If anyone have a file structure spec it would be great.Suter
Z
1

Perhaps you should consider using Illustrator to save files as svg. It seems to be easier to parse SVG than the illustrator format. Examples of manipulation of svg using python (specifically conversion to .png) can be found in other questions, such as the one below.

Convert SVG to PNG in Python

Zymo answered 13/1, 2012 at 22:0 Comment(1)
And what if want to go the opposite way...? Then you need the AI file format as they not support natively everything (like filters?) For your reference: Importing SVG to AI easy fall into error R6025Suter

© 2022 - 2024 — McMap. All rights reserved.