This is a Flask-based API that uses pandoc to convert text to various formats.
- Python 3.x
- pandoc (must be installed on your system)
- pip (Python package manager)
- Docker (optional, for containerized deployment)
-
Install pandoc on your system:
- macOS:
brew install pandoc
- Ubuntu/Debian:
sudo apt-get install pandoc
- Windows: Download from pandoc.org
- macOS:
-
Install Python dependencies:
pip install -r requirements.txt
- Build the Docker image:
docker build -t pandoc-converter .
- Run the container:
docker run -p 5000:5000 pandoc-converter
如果要挂载出来就文件夹/app/uploads映射即可
- Start the server:
# For local installation
python app.py
# For Docker installation
docker run -p 5000:5000 pandoc-converter
- The API will be available at
http://localhost:5000
- URL:
/convert
- Method:
POST
- Content-Type:
application/json
- Request Body:
{
"text": "Your text content here",
"output_format": "pdf" // or any other format supported by pandoc
}
- URL:
/download/<filename>
- Method:
GET
curl -X POST http://localhost:5000/convert \
-H "Content-Type: application/json" \
-d '{"text": "# Hello World\nThis is a test", "output_format": "pdf"}'
The response will include a download URL for the converted file.
The API supports all formats that pandoc can convert to, including:
- HTML
- DOCX
- EPUB
- And many more
- The API includes basic security measures to prevent directory traversal attacks
- Files are stored with unique UUIDs to prevent naming conflicts
- Input validation is performed on all requests
- The Docker image is based on Debian 11.11
- Includes all necessary dependencies for pandoc and PDF generation
- Exposes port 5000 for API access
- Creates a persistent uploads directory for converted files