Skip to main content

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.

📖 中文文档

Documentation

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 use brew install poppler, and on Linux install the poppler-utils package.

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: reads examples/files/example.ai and exports PNG preview.
  • examples/dxf_basic.py: reads examples/files/example.dxf and 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=True forces an RGBA PNG and overrides any background_color.
  • background_color applies only when transparent=False; both PyMuPDF and pdf2image paths will composite the color (requires Pillow).
  • If you prefer PyMuPDF but set background_color without 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

vector2png-0.2.0.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vector2png-0.2.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file vector2png-0.2.0.tar.gz.

File metadata

  • Download URL: vector2png-0.2.0.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for vector2png-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f133868347f72aa13a3cb91d8cbf7e093b7016cf46f1db6c5706c5720a9751e3
MD5 b64bf09ba8fdcc864fb3700f83b55cef
BLAKE2b-256 4b026142e76141b655f86110ba9bc355abd6a1b47fafea2a4f392908fdd65e82

See more details on using hashes here.

File details

Details for the file vector2png-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: vector2png-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for vector2png-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 409f730f2f859a94397b4427a4229cf7e762858ac09641dea8cac0e5dc356592
MD5 fb492d7182b04665bde661a4580a897f
BLAKE2b-256 ecaacc39f1f39154a0d91c864db5e8007d62f70425b7738752d05824fdd5f5e1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page