Skip to main content
The convert command handles single file conversions between supported formats across documents, images, audio, video, and archives.

Syntax

python solution.py convert <input> <output> [options]

Parameters

input
string
required
Path to the input file to convert
output
string
required
Path to the output file (determines output format by extension)
--preserve-original
boolean
default:"false"
Preserve the original file during conversion by creating a temporary copy
--password
string
Password for encrypted documents or password-protected archives

Supported Conversions

Documents

Convert between PDF, DOCX, DOC, TXT, MD, EPUB, PPTX, XLSX, HTML, TEX, XML, BIB, JSON, RST, RTF, ODT, ORG, IPYNB, FB2, ICML, OPML, TEXI, TEXTILE, TYP, MUSE, HS, ADOC, and more. Examples:
python solution.py convert document.docx output.pdf
python solution.py convert report.md presentation.pptx
python solution.py convert thesis.txt formatted.docx
python solution.py convert data.xlsx summary.pdf
python solution.py convert notes.org academic.tex

Images

Convert between JPG, JPEG, PNG, WEBP, GIF, BMP, TIFF, and PDF. Examples:
python solution.py convert photo.png compressed.jpg
python solution.py convert diagram.bmp vector.pdf
python solution.py convert screenshot.webp archive.tiff
python solution.py convert animation.gif static.png

Audio

Convert between MP3, WAV, FLAC, AAC, OGG, and M4A formats. Examples:
python solution.py convert song.mp3 lossless.flac
python solution.py convert podcast.wav compressed.aac
python solution.py convert recording.m4a universal.ogg

Video

Convert between MP4, AVI, MKV, MOV, WMV, FLV, WEBM, and GIF formats. Examples:
python solution.py convert movie.mp4 optimized.webm
python solution.py convert presentation.avi portable.mov
python solution.py convert tutorial.mkv social.gif

Archives

Convert between ZIP, TAR, GZ, BZ2, 7Z, and RAR archive formats. Examples:
python solution.py convert backup.zip extracted.tar.gz
python solution.py convert files.rar compressed.7z

Usage Examples

Basic Conversion

python solution.py convert input.docx output.pdf
Expected Output:
Converting: /path/to/input.docx to /path/to/output.pdf
Success: Document conversion successful: /path/to/output.pdf
Info: Conversion completed in 2.34 seconds.

Preserve Original File

python solution.py convert input.docx output.pdf --preserve-original
This creates a temporary copy of the input file for conversion, ensuring the original remains untouched.

Password-Protected Archives

python solution.py convert protected.zip extracted.tar.gz --password mypassword
python solution.py convert secure.rar backup.7z --password archivepassword
Expected Output:
Converting: /path/to/protected.zip to /path/to/extracted.tar.gz
Password: mypassword
Info: Extracting password-protected archive: /path/to/protected.zip
Success: Archive conversion successful: /path/to/extracted.tar.gz
Info: Conversion completed in 1.87 seconds.

Notes

  • The output format is automatically detected from the file extension
  • Some conversions require external dependencies (LaTeX for PDF, FFmpeg for media)
  • PDF to other formats has limitations due to format complexity
  • File size limits may apply for certain conversion types
  • Archive conversions extract and re-compress the contents

Error Handling

If the output file already exists, you’ll be prompted to confirm overwrite:
Output file /path/to/output.pdf exists. Overwrite? (y/N):
Type y to proceed or N to cancel the operation.

Build docs developers (and LLMs) love