devZenaight commited on
Commit
ec8d47f
Β·
1 Parent(s): 8dc1ac9
app/DocumentGeneration/live_pdf_generator.py CHANGED
@@ -6,7 +6,13 @@ import io
6
  import tempfile
7
  import os
8
  from typing import Dict, Any, Optional, AsyncGenerator
9
- from fpdf2 import FPDF
 
 
 
 
 
 
10
  import base64
11
 
12
  import sys
 
6
  import tempfile
7
  import os
8
  from typing import Dict, Any, Optional, AsyncGenerator
9
+ try:
10
+ from fpdf2 import FPDF
11
+ except ImportError:
12
+ try:
13
+ from fpdf import FPDF
14
+ except ImportError:
15
+ raise ImportError("Neither fpdf2 nor fpdf package found. Please install fpdf2.")
16
  import base64
17
 
18
  import sys
app/DocumentGeneration/pdf_generator.py CHANGED
@@ -39,7 +39,10 @@ def calculate_real_page_numbers(request: ExportRequest, filtered_sections):
39
  try:
40
  from fpdf2 import FPDF
41
  except ImportError:
42
- raise Exception("fpdf2 is not installed. Please install it with: pip install fpdf2")
 
 
 
43
 
44
  # Create temporary PDF to calculate page numbers
45
  temp_pdf = FPDF()
@@ -185,7 +188,10 @@ def create_pdf_document(request: ExportRequest):
185
  try:
186
  from fpdf2 import FPDF
187
  except ImportError:
188
- raise Exception("fpdf2 is not installed. Please install it with: pip install fpdf2")
 
 
 
189
 
190
  # Filter out empty sections to prevent blank pages
191
  try:
 
39
  try:
40
  from fpdf2 import FPDF
41
  except ImportError:
42
+ try:
43
+ from fpdf import FPDF
44
+ except ImportError:
45
+ raise Exception("Neither fpdf2 nor fpdf package found. Please install fpdf2.")
46
 
47
  # Create temporary PDF to calculate page numbers
48
  temp_pdf = FPDF()
 
188
  try:
189
  from fpdf2 import FPDF
190
  except ImportError:
191
+ try:
192
+ from fpdf import FPDF
193
+ except ImportError:
194
+ raise Exception("Neither fpdf2 nor fpdf package found. Please install fpdf2.")
195
 
196
  # Filter out empty sections to prevent blank pages
197
  try:
app/main.py CHANGED
@@ -116,7 +116,6 @@ sys.path.append(os.path.join(os.path.dirname(__file__), 'CurrencyMapping'))
116
 
117
  from DocumentGeneration.pdf_generator import create_pdf_document
118
  from DocumentGeneration.word_generator import create_word_document
119
- from DocumentGeneration.live_pdf_generator import live_pdf_generator
120
  from DocumentGeneration.chart_generator import parse_embedded_chart_data, create_chart_from_data
121
  from DocumentGeneration.table_of_content import generate_table_of_contents_after_content, add_table_of_contents_page
122
  from DocumentGeneration.document_helpers import (
@@ -1600,73 +1599,73 @@ async def download_file(filename: str):
1600
  # Live PDF Generation Endpoints
1601
  # ──────────────────────────────────────────────────────────────────────────────
1602
 
1603
- @app.post("/live-pdf/start")
1604
- async def start_live_pdf_session(request: Request, data: ExportRequest):
1605
- """Start a live PDF session that streams updates as content changes"""
1606
- try:
1607
- # Create a new live PDF session
1608
- session_id = await live_pdf_generator.create_live_session(
1609
- data.businessIdea or "default",
1610
- data
1611
- )
1612
-
1613
- return {
1614
- "success": True,
1615
- "session_id": session_id,
1616
- "message": "Live PDF session started successfully"
1617
- }
1618
-
1619
- except Exception as e:
1620
- raise HTTPException(status_code=500, detail=f"Failed to start live PDF session: {str(e)}")
1621
-
1622
- @app.post("/live-pdf/update/{session_id}")
1623
- async def update_live_pdf_session(session_id: str, data: ExportRequest):
1624
- """Update an existing live PDF session with new content"""
1625
- try:
1626
- success = await live_pdf_generator.update_session(session_id, data)
1627
-
1628
- if not success:
1629
- raise HTTPException(status_code=404, detail="Session not found")
1630
-
1631
- return {
1632
- "success": True,
1633
- "message": "PDF updated successfully"
1634
- }
1635
-
1636
- except Exception as e:
1637
- raise HTTPException(status_code=500, detail=f"Failed to update PDF: {str(e)}")
1638
-
1639
- @app.get("/live-pdf/stream/{session_id}")
1640
- async def stream_live_pdf_updates(session_id: str):
1641
- """Stream live PDF updates using Server-Sent Events"""
1642
- async def event_generator():
1643
- async for chunk in live_pdf_generator.stream_pdf_updates(session_id):
1644
- yield chunk
1645
-
1646
- return StreamingResponse(
1647
- event_generator(),
1648
- media_type="text/event-stream",
1649
- headers={
1650
- "Cache-Control": "no-cache",
1651
- "Connection": "keep-alive",
1652
- "Access-Control-Allow-Origin": "*",
1653
- "Access-Control-Allow-Headers": "*"
1654
- }
1655
- )
1656
-
1657
- @app.delete("/live-pdf/close/{session_id}")
1658
- async def close_live_pdf_session(session_id: str):
1659
- """Close and cleanup a live PDF session"""
1660
- try:
1661
- live_pdf_generator.close_session(session_id)
1662
-
1663
- return {
1664
- "success": True,
1665
- "message": "Live PDF session closed successfully"
1666
- }
1667
-
1668
- except Exception as e:
1669
- raise HTTPException(status_code=500, detail=f"Failed to close session: {str(e)}")
1670
  @app.get("/")
1671
  def root():
1672
  return {"status": "FastAPI is running πŸš€"}
 
116
 
117
  from DocumentGeneration.pdf_generator import create_pdf_document
118
  from DocumentGeneration.word_generator import create_word_document
 
119
  from DocumentGeneration.chart_generator import parse_embedded_chart_data, create_chart_from_data
120
  from DocumentGeneration.table_of_content import generate_table_of_contents_after_content, add_table_of_contents_page
121
  from DocumentGeneration.document_helpers import (
 
1599
  # Live PDF Generation Endpoints
1600
  # ──────────────────────────────────────────────────────────────────────────────
1601
 
1602
+ # @app.post("/live-pdf/start")
1603
+ # async def start_live_pdf_session(request: Request, data: ExportRequest):
1604
+ # """Start a live PDF session that streams updates as content changes"""
1605
+ # try:
1606
+ # # Create a new live PDF session
1607
+ # session_id = await live_pdf_generator.create_live_session(
1608
+ # data.businessIdea or "default",
1609
+ # data
1610
+ # )
1611
+ #
1612
+ # return {
1613
+ # "success": True,
1614
+ # "session_id": session_id,
1615
+ # "message": "Live PDF session started successfully"
1616
+ # }
1617
+ #
1618
+ # except Exception as e:
1619
+ # raise HTTPException(status_code=500, detail=f"Failed to start live PDF session: {str(e)}")
1620
+
1621
+ # @app.post("/live-pdf/update/{session_id}")
1622
+ # async def update_live_pdf_session(session_id: str, data: ExportRequest):
1623
+ # """Update an existing live PDF session with new content"""
1624
+ # try:
1625
+ # success = await live_pdf_generator.update_session(session_id, data)
1626
+ #
1627
+ # if not success:
1628
+ # raise HTTPException(status_code=404, detail="Session not found")
1629
+ #
1630
+ # return {
1631
+ # "success": True,
1632
+ # "message": "PDF updated successfully"
1633
+ # }
1634
+ #
1635
+ # except Exception as e:
1636
+ # raise HTTPException(status_code=500, detail=f"Failed to update PDF: {str(e)}")
1637
+
1638
+ # @app.get("/live-pdf/stream/{session_id}")
1639
+ # async def stream_live_pdf_updates(session_id: str):
1640
+ # """Stream live PDF updates using Server-Sent Events"""
1641
+ # async def event_generator():
1642
+ # async for chunk in live_pdf_generator.stream_pdf_updates(session_id):
1643
+ # yield chunk
1644
+ #
1645
+ # return StreamingResponse(
1646
+ # event_generator(),
1647
+ # media_type="text/event-stream",
1648
+ # headers={
1649
+ # "Cache-Control": "no-cache",
1650
+ # "Connection": "keep-alive",
1651
+ # "Access-Control-Allow-Origin": "*",
1652
+ # "Access-Control-Allow-Headers": "*"
1653
+ # }
1654
+ # )
1655
+
1656
+ # @app.delete("/live-pdf/close/{session_id}")
1657
+ # async def close_live_pdf_session(session_id: str):
1658
+ # """Close and cleanup a live PDF session"""
1659
+ # try:
1660
+ # live_pdf_generator.close_session(session_id)
1661
+ #
1662
+ # return {
1663
+ # "success": True,
1664
+ # "message": "Live PDF session closed successfully"
1665
+ # }
1666
+ #
1667
+ # except Exception as e:
1668
+ # raise HTTPException(status_code=500, detail=f"Failed to close session: {str(e)}")
1669
  @app.get("/")
1670
  def root():
1671
  return {"status": "FastAPI is running πŸš€"}
requirements.txt CHANGED
@@ -12,7 +12,7 @@ supabase>=2.6.0
12
  asyncpg
13
  python-jose[cryptography]
14
  python-docx==0.8.11
15
- fpdf2
16
  Pillow==10.0.0
17
  requests
18
  PyJWT
 
12
  asyncpg
13
  python-jose[cryptography]
14
  python-docx==0.8.11
15
+ fpdf2>=2.7.0
16
  Pillow==10.0.0
17
  requests
18
  PyJWT