Files
SaaS-PDF/backend/app/services/html_to_pdf_service.py
Your Name d7f6228d7f الميزات: إضافة أدوات جديدة لمعالجة ملفات PDF، تشمل التلخيص والترجمة واستخراج الجداول.
- تفعيل مكون SummarizePdf لإنشاء ملخصات PDF باستخدام الذكاء الاصطناعي.

- تفعيل مكون TranslatePdf لترجمة محتوى PDF إلى لغات متعددة.

- تفعيل مكون TableExtractor لاستخراج الجداول من ملفات PDF.

- تحديث الصفحة الرئيسية والتوجيه ليشمل الأدوات الجديدة.

- إضافة ترجمات للأدوات الجديدة باللغات الإنجليزية والعربية والفرنسية.

- توسيع أنواع واجهة برمجة التطبيقات (API) لدعم الميزات الجديدة المتعلقة بمعالجة ملفات PDF. --feat: Initialize frontend with React, Vite, and Tailwind CSS

- Set up main entry point for React application.
- Create About, Home, NotFound, Privacy, and Terms pages with SEO support.
- Implement API service for file uploads and task management.
- Add global styles using Tailwind CSS.
- Create utility functions for SEO and text processing.
- Configure Vite for development and production builds.
- Set up Nginx configuration for serving frontend and backend.
- Add scripts for cleanup of expired files and sitemap generation.
- Implement deployment script for production environment.
2026-03-08 05:49:09 +02:00

85 lines
1.9 KiB
Python

"""HTML to PDF conversion service."""
import os
import logging
logger = logging.getLogger(__name__)
class HtmlToPdfError(Exception):
"""Custom exception for HTML to PDF conversion failures."""
pass
def html_to_pdf(
input_path: str,
output_path: str,
) -> dict:
"""
Convert an HTML file to PDF.
Args:
input_path: Path to the input HTML file
output_path: Path for the output PDF
Returns:
dict with output_size
Raises:
HtmlToPdfError: If conversion fails
"""
os.makedirs(os.path.dirname(output_path), exist_ok=True)
try:
from weasyprint import HTML
HTML(filename=input_path).write_pdf(output_path)
output_size = os.path.getsize(output_path)
logger.info(f"HTML→PDF conversion completed ({output_size} bytes)")
return {
"output_size": output_size,
}
except ImportError:
raise HtmlToPdfError("weasyprint library is not installed.")
except Exception as e:
raise HtmlToPdfError(f"Failed to convert HTML to PDF: {str(e)}")
def html_string_to_pdf(
html_content: str,
output_path: str,
) -> dict:
"""
Convert an HTML string to PDF.
Args:
html_content: HTML content as string
output_path: Path for the output PDF
Returns:
dict with output_size
Raises:
HtmlToPdfError: If conversion fails
"""
os.makedirs(os.path.dirname(output_path), exist_ok=True)
try:
from weasyprint import HTML
HTML(string=html_content).write_pdf(output_path)
output_size = os.path.getsize(output_path)
logger.info(f"HTML string→PDF conversion completed ({output_size} bytes)")
return {
"output_size": output_size,
}
except ImportError:
raise HtmlToPdfError("weasyprint library is not installed.")
except Exception as e:
raise HtmlToPdfError(f"Failed to convert HTML to PDF: {str(e)}")