A comprehensive file format conversion toolkit supporting documents, images, and spreadsheets.
Activate this skill when any of these scenarios occur:
Source FormatTarget FormatScriptNotes.pdf``.docx``scripts/pdf_to_word.pyExtracts text, tables, layout.docx, .doc``.pdf``scripts/word_to_pdf.pyRequires MS Word on WindowsPNG/JPEG/WebP/BMP/GIF/TIFFAny other image formatscripts/image_converter.pyQuality control, resize support.csv``.xlsx``scripts/excel_csv_converter.pyCustom delimiter/encoding.xlsx, .xls``.csv``scripts/excel_csv_converter.pyMulti-sheet support
Install required packages before first use:
bash
pip install Pillow pdf2docx docx2pdf openpyxl xlrd
Quick install command:
bash
pip install Pillow pdf2docx docx2pdf openpyxl xlrd
docx2pdf uses COM automation)pdf2docxPillow only, works on all platformsDetermine what the user wants to convert:
text
User says "convert this PDF" → PDF to Word
User says "turn this into PDF" → Word to PDF
User says "change this PNG to JPG" → Image conversion
User says "export this Excel as CSV" → Excel to CSV
Before running any script, verify required packages are installed:
bash
python -c "import PIL; import pdf2docx; import docx2pdf; import openpyxl"
If imports fail, prompt user to run:
bash
pip install Pillow pdf2docx docx2pdf openpyxl xlrd
Single file:
bash
python scripts/pdf_to_word.py <input.pdf> [output.docx]
Batch mode:
bash
python scripts/pdf_to_word.py --batch ./pdf_folder --output-dir ./output_folder
Options:
--start N: Start from page N (default: 0)--end N: End at page N (default: all pages)Single file:
bash
python scripts/word_to_pdf.py <input.docx> [output.pdf]
Batch mode:
bash
python scripts/word_to_pdf.py --batch ./docs_folder --output-dir ./pdfs_folder
Check requirements:
bash
python scripts/word_to_pdf.py --check
Single file:
bash
python scripts/image_converter.py <input_image> --format <target_format>
Batch mode:
bash
python scripts/image_converter.py --batch ./images_dir --format webp --output-dir ./webp_dir
Target formats: png, jpg/ jpeg, webp, bmp, gif, tiff/ tif
Options:
-q/--quality N: Quality for lossy formats (1-100, default: 95)--resize WIDTH HEIGHT: Resize dimensions--no-optimize: Disable optimization--info: Display image info without convertingExamples:
bash
# High-quality JPEG compression
python scripts/image_converter.py photo.png --format jpg -q 90
# Convert to WebP with smaller size
python scripts/image_converter.py photo.png --format webp -q 80
# Resize while converting
python scripts/image_converter.py large.png --format jpg --resize 1920 1080
# View image info
python scripts/image_converter.py image.png --info
CSV → Excel:
bash
python scripts/excel_csv_converter.py data.csv --format xlsx [options]
Excel → CSV:
bash
python scripts/excel_csv_converter.py data.xlsx --format csv [options]
Batch mode:
bash
python scripts/excel_csv_converter.py --batch ./data_dir --format csv
Options:
-d/--delimiter CHAR: Custom separator (default: comma)-e/--encoding ENC: File encoding (default: utf-8)--sheet NAME: Specific sheet name (Excel→CSV)--sheet-name NAME: Output sheet name (CSV→Excel)--no-header: Skip header row--info: Show Excel structure infoExamples:
bash
# European-style CSV (semicolon delimited)
python scripts/excel_csv_converter.py data.csv --format xlsx -d ";"
# Chinese encoding support
python scripts/excel_csv_converter.py data.xlsx --format csv -e gbk
# Export specific sheet
python scripts/excel_csv_converter.py workbook.xlsx --format csv -s "Sales Report"
# View Excel info
python scripts/excel_csv_converter.py data.xlsx --info
After each conversion:
ErrorCauseSolutionModuleNotFoundErrorMissing packageRun pip install <package>``COMError (Word→PDF)MS Word not installedInstall MS Office or use alternativeUnicodeDecodeErrorWrong encodingSpecify correct --encoding``FileNotFoundErrorWrong pathVerify input path is absolute or relative correctlyPermission deniedRead-only directoryUse writable output directory
When dealing with non-UTF-8 files, common encodings:
gbk / gb18030latin-1 / cp1252shift-jis / cp932utf-8 first, then fallback