E-Book MCP Server with PDF Conversion
LocalAbout E-Book MCP Server with PDF Conversion
An MCP server for creating PDFs from HTML documents with embedded images. It supports PDF generation through pdfkit or reportlab, with a fallback to reportlab when pdfkit is unavailable or fails.
Key features
- 01Convert HTML files to PDF
- 02Handle embedded image references
- 03Generate PDFs with pdfkit or reportlab
- 04Fall back to reportlab on conversion failure
- 05Clean up temporary files
Use cases
- 01Create a PDF from an HTML document
- 02Convert HTML containing images into a PDF
- 03Generate PDFs when pdfkit is unavailable
MCP support
Provides a CREATE_DOC tool for HTML-to-PDF conversion, including image path handling.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEE-Book MCP Server with PDF Conversion
A server for creating e-books and PDF documents from HTML content with embedded images. This project provides robust functionality for converting HTML files to PDF while properly handling embedded images.
Features
- Convert HTML files to PDF documents with proper image handling
- Support for both pdfkit (wkhtmltopdf) and reportlab PDF generation engines
- Robust error handling and logging
- Temporary file management with automatic cleanup
- Detailed diagnostic information during conversion process
Requirements
- Python 3.9+
- wkhtmltopdf (optional but recommended for better PDF quality)
- Python packages:
- fastapi
- python-docx
- pdfkit
- reportlab
- pydantic
- uvicorn
- pillow
Installation
- Clone this repository
- Install the required Python packages:
pip install fastapi python-docx pdfkit reportlab pydantic uvicorn pillow - Install wkhtmltopdf (optional):
- Windows: Download and install from wkhtmltopdf.org
- Linux:
sudo apt-get install wkhtmltopdf - macOS:
brew install wkhtmltopdf
Usage
The server provides a function called handle_call_tool that accepts the following arguments:
arguments = {
"text_file": "path/to/input.html",
"images": {
"image1.png": "path/to/image1.png",
"image2.jpg": "path/to/image2.jpg"
},
"output_pdf": "path/to/output.pdf"
}
Example
result = await handle_call_tool("CREATE_DOC", {
"text_file": "document.html",
"images": {
"header.png": "images/header.png",
"footer.jpg": "images/footer.jpg"
},
"output_pdf": "output/document.pdf"
})
How It Works
- The server processes the input HTML file
- It replaces image references in the HTML with absolute paths
- It attempts to convert the HTML to PDF using pdfkit (if available)
- If pdfkit fails or is not available, it falls back to reportlab
- The resulting PDF is saved to the specified output path
Project Structure
main.py: Contains the core functionality for PDF conversionpyproject.toml: Project metadata and dependencies
License
MIT
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.