A versatile command-line tool to convert between Office formats and PDF.
- π Convert Office documents to PDF (DOCX, PPTX, XLSX, ODS, ODT, ODP, TXT, RTF, CSV)
- π Convert PDF back to Office formats (DOCX, PPTX)
- π Batch conversion support for processing multiple files
- π¨ Colored output for better readability
- β‘ Cross-platform support (macOS, Linux)
- π Shell completion for Bash and Zsh
# Add the tap first
brew tap shar-mayank/tools
# Install convert2pdf
brew install convert2pdfOr install directly:
brew install shar-mayank/tools/convert2pdf-
Clone the repository:
git clone https://github.com/shar-mayank/convert2pdf.git cd convert2pdf -
Make the script executable:
chmod +x convert2pdf
-
Install dependencies:
./convert2pdf --setup
-
Move to a directory in your PATH (optional, for global access):
sudo cp convert2pdf /usr/local/bin/
-
(Optional) Install shell completions:
# For Bash sudo cp completions/convert2pdf.bash /usr/local/etc/bash_completion.d/convert2pdf # For Zsh sudo cp completions/convert2pdf.zsh /usr/local/share/zsh/site-functions/_convert2pdf
- LibreOffice - Used for document format conversions
- Python 3 (3.8 or later) - For PDF to Office format conversions
These are installed automatically with --setup:
pdf2docx(0.5.8) - For PDF to DOCX conversionPyPDF2(3.0.1) - For reading PDF filespython-pptx(1.0.2) - For creating PPTX filesnumpy(<2.0) - Required by pdf2docx
# macOS
brew install --cask libreoffice
# Ubuntu/Debian
sudo apt-get install libreoffice
# Fedora
sudo dnf install libreoffice
# CentOS/RHEL
sudo yum install libreofficeConvert an Office document to PDF:
convert2pdf document.docxSpecify output filename:
convert2pdf presentation.pptx output.pdfConvert PDF to Office format:
convert2pdf document.pdf
# You'll be prompted to choose DOCX or PPTX output formatConvert all DOCX files in current directory to PDF:
convert2pdf --batch "*.docx"Convert files in one directory and save to another:
convert2pdf --batch "reports/*.pptx" pdfs/Options:
-h, --help Show help message
-v, --version Show version information
--setup Install required dependencies
--batch Process multiple files matching the input pattern
To PDF:
- Word:
.doc,.docx - PowerPoint:
.ppt,.pptx - Excel:
.xls,.xlsx - OpenDocument:
.odt,.odp,.ods - Text:
.txt,.rtf,.csv
From PDF:
- Word Document:
.docx - PowerPoint:
.pptx
-
Convert Word document to PDF:
convert2pdf document.docx
-
Convert PowerPoint presentation to PDF with custom name:
convert2pdf presentation.pptx slides.pdf
-
Convert PDF to Word document:
convert2pdf report.pdf report.docx
-
Convert all Excel files in a directory to PDF:
convert2pdf --batch "financials/*.xlsx" pdf_reports/
- PDF to Office conversions preserve text content but may not perfectly maintain all formatting and layout
- Images in PDFs may not be preserved when converting to Office formats
This tool includes shell completion for:
- Bash: Command options and file completion
- Zsh: Command options and file completion
When installed via Homebrew, completion scripts are automatically installed.
For manual installation, see the Installation section.
Run the test suite to verify the installation:
./test/test_convert2pdf.sh
# For verbose output
./test/test_convert2pdf.sh --verboseMake sure LibreOffice is installed and accessible. On macOS, it should be in /Applications/LibreOffice.app.
Run convert2pdf --setup to install required Python packages automatically.
Make sure the script is executable: chmod +x convert2pdf
MIT License - see LICENSE file for details.
Mayank Sharma - GitHub
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request