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.

📖 中文文档

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.

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.1.0.tar.gz (15.8 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.1.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for vector2png-0.1.0.tar.gz
Algorithm Hash digest
SHA256 eefaa06452f5caa86aea4eebf6aa88a996befeb6a095d59504fb933e6f310b69
MD5 158906938a7dde0d8c6c07715039a753
BLAKE2b-256 d38649d2e72b3d8bb79c01cf4cc0ea5826fd5b54547f1edd0e3ad31401880ab8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: vector2png-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b036c038655d7093e4cd4c4bd21bb110ed7503d65a80bbcd98d2919914233298
MD5 02db4a18d48f5425b134992b1b1baa7b
BLAKE2b-256 50258c21ada3fd346d7fa0b0cc4a9824092a9962e3e4b526a2c54c709bb7ab34

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