by moonboy
PDF to ePub Converter
import logging
from gunicorn.app.base import BaseApplication
from app_init import create_initialized_flask_app
import sys
# Flask app creation should be done by create_initialized_flask_app to avoid circular dependency problems.
app = create_initialized_flask_app()
# Setup logging
logging.basicConfig(level=logging.INFO, stream=sys.stdout,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
class StandaloneApplication(BaseApplication):
def __init__(self, app, options=None):
self.application = app
self.options = options or {}
super().__init__()
def load_config(self):
# Apply configuration to Gunicorn
for key, value in self.options.items():
if key in self.cfg.settings and value is not None:
self.cfg.set(key.lower(), value)
PDF to ePub Converter
Created: | Last Updated:
Here's a step-by-step guide for using the PDF to ePub Converter template:
Introduction
This template provides a web application for converting PDF files to ePub format. It features a user-friendly upload interface and handles the conversion process server-side.
Getting Started
- Click "Start with this Template" to begin using the PDF to ePub Converter template in the Lazy Builder interface.
Test the Application
- Press the "Test" button in the Lazy Builder interface to deploy the application and launch the Lazy CLI.
Using the PDF to ePub Converter
-
Once the application is deployed, you'll receive a dedicated server link to access the web interface.
-
Open the provided link in your web browser to access the PDF to ePub Converter interface.
-
Use the file upload form to select and upload a PDF file you want to convert.
-
After uploading, click the "Convert to ePub" button to start the conversion process.
-
Once the conversion is complete, the application will automatically download the converted ePub file to your device.
Integration (Optional)
This application is designed to be used as a standalone web service. There are no additional integration steps required for its basic functionality. However, if you want to incorporate this conversion capability into another application or service, you can do so by making HTTP requests to the server.
Here's a sample code snippet for integrating the PDF to ePub conversion into another application using Python and the requests
library:
```python import requests
def convert_pdf_to_epub(pdf_file_path, server_url): # Upload the PDF file with open(pdf_file_path, 'rb') as pdf_file: files = {'pdf_file': pdf_file} response = requests.post(f"{server_url}/upload", files=files)
if response.status_code == 200:
# Trigger the conversion
response = requests.post(f"{server_url}/convert")
if response.status_code == 200:
# Save the converted ePub file
with open('converted.epub', 'wb') as epub_file:
epub_file.write(response.content)
print("Conversion successful. ePub file saved as 'converted.epub'")
else:
print("Conversion failed")
else:
print("File upload failed")
Usage example
server_url = "YOUR_SERVER_URL_HERE" pdf_file_path = "path/to/your/pdf/file.pdf" convert_pdf_to_epub(pdf_file_path, server_url) ```
Replace "YOUR_SERVER_URL_HERE"
with the actual server URL provided by the Lazy platform when you deploy the application.
This integration allows you to programmatically convert PDF files to ePub format using the deployed PDF to ePub Converter service.