bluenevus commited on
Commit
69b83fd
·
verified ·
1 Parent(s): 9deeacf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -21,6 +21,8 @@ import ssl
21
  from io import BytesIO
22
  from concurrent.futures import ThreadPoolExecutor
23
  import math
 
 
24
 
25
  # Initialize Dash app
26
  app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
@@ -199,13 +201,16 @@ async def website_to_pdf(all_pages, progress_callback):
199
  except Exception as e:
200
  logger.error(f"Error generating PDF chunk {i}: {str(e)}")
201
 
202
- # Combine PDF chunks
203
- combined_pdf = FPDF()
204
  for chunk in pdf_chunks:
205
- combined_pdf.add_page()
206
- combined_pdf.put_file(chunk)
 
 
 
207
 
208
- return combined_pdf.output(dest='S').encode('latin-1')
209
 
210
  async def process_url(url, depth, progress_callback):
211
  try:
 
21
  from io import BytesIO
22
  from concurrent.futures import ThreadPoolExecutor
23
  import math
24
+ from PyPDF2 import PdfMerger
25
+
26
 
27
  # Initialize Dash app
28
  app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
 
201
  except Exception as e:
202
  logger.error(f"Error generating PDF chunk {i}: {str(e)}")
203
 
204
+ # Combine PDF chunks using PyPDF2
205
+ merger = PdfMerger()
206
  for chunk in pdf_chunks:
207
+ merger.append(BytesIO(chunk))
208
+
209
+ output = BytesIO()
210
+ merger.write(output)
211
+ merger.close()
212
 
213
+ return output.getvalue()
214
 
215
  async def process_url(url, depth, progress_callback):
216
  try: