Convert CSV files to high-quality PNG/JPEG images with full Unicode support (CJK, Arabic, Hebrew, Devanagari, etc.).
- Simple API: Convert CSV to PNG/JPEG with one line of code
- High Quality: Configurable DPI (default 300) for crisp output
- Full Unicode: Auto-detects scripts and uses appropriate fonts — CJK, Arabic, Hebrew, Devanagari, Latin Extended
- Multi-page Support: Automatically handles CSV files that span multiple pages
- Flexible Formats: Output as PNG or JPEG
- Custom Delimiters: Supports TSV, semicolon-separated, or any delimiter
- CLI Support: Use from command line or as a Python library
- Zero csv2pdf dependency: Pure fpdf2 + PyMuPDF
pip install csv2imggit clone https://github.com/Shun-Calvin/csv2img.git
cd csv2img
pip install -e .from csv2img import saveas
# Convert a CSV file to PNG images
output_files = saveas("data.csv")
print(f"Generated {len(output_files)} images: {output_files}")from csv2img import saveas
# Chinese/Japanese/Korean text is auto-detected and rendered with Noto Sans CJK
output_files = saveas("chinese_data.csv")
# Output: chinese_data1.png (with proper CJK characters)from csv2img import saveas
# Convert to JPEG at 600 DPI
output_files = saveas("report.csv", dpi=600, output_format="jpeg")from csv2img import saveas
# Tab-separated values
output_files = saveas("data.tsv", delimiter="\t")
# Semicolon-separated (common in European locales)
output_files = saveas("data.csv", delimiter=";")from csv2img import saveas
# Use your own TTF/OTF font file
output_files = saveas("data.csv", font_path="/path/to/your/font.ttf")from csv2img import convert_file
output_files = convert_file("data.csv", output_dir="./images", dpi=300)After installation, you can use the csv2img command:
# Basic usage
csv2img data.csv
# Specify output directory
csv2img data.csv ./output
# Specify output directory and DPI
csv2img data.csv ./output 600
# Specify output format
csv2img data.csv ./output 300 --format jpeg
# Specify delimiter (TSV)
csv2img data.csv ./output 300 --delimiter $'\t'
# Custom font
csv2img data.csv ./output 300 --font /path/to/font.ttfConvert a CSV file to image files.
Parameters:
source(str | Path): Path to the source CSV file (required)dpi(int): Resolution for output images (default: 300)output_dir(str, optional): Directory to save output images (default: same as source)output_format(str): Output format —'png'or'jpeg'(default:'png')delimiter(str): CSV delimiter character (default:',')font_path(str, optional): Path to a TTF/OTF font file. IfNone, auto-detects from system fonts based on CSV content.
Returns:
List[str]: List of paths to the generated image files
Raises:
FileNotFoundError: If the source CSV file doesn't existValueError: If the source file is not a CSV file or format is unsupportedImportError: If required dependencies are not installed
A list of supported output formats: ["png", "jpeg", "jpg"]
csv2img auto-detects the dominant script in your CSV and uses the appropriate font:
| Script | Unicode Range | Font Used |
|---|---|---|
| CJK (Chinese/Japanese/Korean) | \u4e00-\u9fff, \u3040-\u30ff |
Noto Sans CJK |
| Arabic | \u0600-\u06ff |
Noto Sans Arabic |
| Hebrew | \u0590-\u05ff |
Noto Sans Hebrew |
| Devanagari (Hindi, etc.) | \u0900-\u097f |
Noto Sans Devanagari |
| Latin Extended | \u0080-\u024f |
Noto Sans Mono |
You can override auto-detection by passing font_path explicitly.
- The CSV file is parsed using Python's built-in
csvmodule (supports any delimiter) - fpdf2 renders the table to a PDF with Unicode-aware TTF fonts
- PyMuPDF (fitz) renders each PDF page as a high-quality image
- The temporary PDF file is automatically cleaned up
Example:
- Input:
data.csv - Output:
data1.png,data2.png,data3.png(if the CSV spans 3 pages)
- Python 3.7+
- fpdf2 (PDF rendering with Unicode font support)
- PyMuPDF (PDF to image rendering)
If your CSV contains characters not covered by the auto-detected font, pass a custom font:
from csv2img import saveas
# Use a font that covers your specific characters
output_files = saveas("data.csv", font_path="/path/to/font.ttf")Ensure you have write permissions in the output directory. If specifying a custom output directory, it will be created automatically if it doesn't exist.
For very large CSV files:
- Reduce the DPI setting (e.g., use 150 instead of 300)
- Ensure sufficient disk space for temporary PDF and output images
pip install pytest
python -m pytest tests/ -v- ✨ Removed csv2pdf dependency — pure fpdf2 + PyMuPDF implementation
- ✨ Full Unicode support — auto-detects CJK, Arabic, Hebrew, Devanagari, Latin Extended
- ✨ JPEG output format — PNG and JPEG both supported
- ✨ Custom delimiter — TSV, semicolon, or any separator
- ✨ Custom font path — pass your own TTF/OTF font file
- ✨ Path object support —
sourceacceptsstrorPath - ✨ Empty CSV handling — returns
[]instead of crashing - ✨ Output validation — verifies generated files exist and are non-empty
- 🐛 Fixed PDF cleanup — removes temp PDF after return, not in finally
- 📦 Updated dependencies —
csv2pdf>=1.0.0→fpdf2>=2.5.0
- Added JPEG and PNG format support
- Added delimiter parameter
- Improved error handling and output validation
- ✨ Added comprehensive error handling and input validation
- ✨ Added type hints and docstrings
- ✨ Added logging support
- ✨ Added command-line interface
- ✨ Added
setup.pyfor proper package installation - ✨ Added
requirements.txt - ✨ Improved documentation with examples
- 🐛 Fixed temporary PDF cleanup
- 📦 Added proper package structure
- Initial release
- Basic CSV to PNG conversion functionality
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request