Convert AI and DXF files into crisp PNG images
Project description
vector2png
Elegant Python utilities to transform Adobe Illustrator (.ai) and AutoCAD DXF (.dxf) files into crisp PNG previews. The project focuses on a polished developer experience with both programmatic and CLI workflows, documented in detail under docs/ with quickstart, CLI, API, and troubleshooting guides. The scope is 2D vector content (lines, shapes, text, gradients); 3D objects or heavy effects are not rendered—flatten or project them upstream before conversion.
Project Links
Documentation
- Overview
- Quickstart
- CLI Guide
- API Reference
- Options Deep Dive
- Dependencies
- Troubleshooting
- FAQ
- Architecture
- Contributing
Highlights
- Intuitive functional API (
vector2png.ai_to_png,vector2png.dxf_to_png) plus configurable converter classes - Dual rendering strategy for AI files (PyMuPDF and pdf2image) with graceful fallback logic
- DXF rendering powered by
ezdxf+PyMuPdfBackend, supporting custom layouts, page sizes, and color policies - Lightweight CLI for quick conversions directly from the terminal
- Optional extras to keep the base install lean (
pip install vector2png[ai],vector2png[dxf])
Installation
pip install vector2png # installs the PyMuPDF core
pip install vector2png[ai] # adds pdf2image + Pillow for the AI pipeline
pip install vector2png[dxf] # adds ezdxf for DXF rendering
pip install vector2png[full] # pulls in every optional dependency
pdf2image requires Poppler. On Windows install
pdftoppm.exe(e.g., via OSGeo4W), on macOS usebrew install poppler, and on Linux install thepoppler-utilspackage.
License Notice
PyMuPDF (MuPDF) ships under the AGPLv3 by default. Because vector2png depends on PyMuPDF for both AI and DXF rendering, anyone redistributing or offering services built on this project must comply with the AGPL requirements or obtain a commercial MuPDF license from Artifex. MIT licensing only covers the code in this repository and does not waive the obligations imposed by PyMuPDF.
Quick Start
Python API
from vector2png import ai_to_png, dxf_to_png, AIOptions, DXFOptions
# AI example
ai_to_png("logo.ai", "logo.png", AIOptions(dpi=200, transparent=True))
# DXF example with custom layout
options = DXFOptions(layout_name="ISO_A1", background="white", color_policy="monochrome")
dxf_to_png("floorplan.dxf", "floorplan.png", options)
CLI
vector2png ai source.ai output.png --dpi 200 --transparent
vector2png dxf drawing.dxf output.png --layout Layout1 --color monochrome
# Optional DXF helpers:
# --pdsize 2.5 # explicit point size to silence ezdxf relative-size notice
# --normalize-relative-size # expand MTEXT relative \\H...x markers to absolute sizes
Run vector2png --help to see all flags and defaults.
Example Scripts
The examples/ directory contains simple scripts:
examples/ai_basic.py: readsexamples/files/example.aiand exports PNG preview.examples/dxf_basic.py: readsexamples/files/example.dxfand exports PNG preview.
Configuration Overview
| Converter | Key options |
|---|---|
| AI | dpi, transparent, background_color, prefer_method, fallback |
| DXF | dpi, background, color_policy, scale, layout_name, page_width, page_height, margins, lineweight_scaling, max_width, max_height, pdsize, normalize_relative_size |
Every option is exposed through the corresponding dataclass (AIOptions, DXFOptions) so IDEs can offer autocomplete and validation.
Background handling for AI conversions:
transparent=Trueforces an RGBA PNG and overrides anybackground_color.background_colorapplies only whentransparent=False; both PyMuPDF and pdf2image paths will composite the color (requires Pillow).- If you prefer PyMuPDF but set
background_colorwithout Pillow installed, a dependency error will be raised.
Error Handling
All Runtime errors funnel through ConversionError (or the more specific DependencyMissingError). When an optional dependency is missing, the error message explains which extra to install. The CLI echoes the same error text and exits with a non-zero status code.
Roadmap Ideas
- SVG and PDF conversion support using the same interface
- Batch-processing helpers with concurrency controls
- Richer diagnostic logging (page bounding boxes, render duration)
Acknowledgements
- PyMuPDF (MuPDF) for high-quality PDF/AI rendering.
- pdf2image and Pillow for the alternate AI pipeline.
- ezdxf for DXF parsing and drawing helpers.
- The broader open-source community for testing tools and inspiration.
Contributions and suggestions are welcome!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vector2png-0.2.2.tar.gz.
File metadata
- Download URL: vector2png-0.2.2.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59fc131b9e379e7ccc87155a19dc3902d22345a5a365ec2754e7075d498191d7
|
|
| MD5 |
01757c7ee7509435fb2b46a97315b754
|
|
| BLAKE2b-256 |
1c426cb022a5a84c55be8299d3fa5f3a4e801a8b2b15bcc8acd9f239e0375041
|
File details
Details for the file vector2png-0.2.2-py3-none-any.whl.
File metadata
- Download URL: vector2png-0.2.2-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cec1b26a00d44693473b7788f5d70fa60335184a6bdc8f86c25e5978b1af7adf
|
|
| MD5 |
33b9f3ebef3469be3d4753c07caf37af
|
|
| BLAKE2b-256 |
3911a9be7e15a3b57dfff6d306906f64c06b006de0b458fefc8c9239bf376a5a
|