gene commited on
Commit
d074dd4
·
1 Parent(s): 02b2d80

pdf to image

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -14,6 +14,9 @@ def convert_pdf_to_image(pdf_file):
14
  # Open the PDF file
15
  pdf_document = fitz.open(pdf_file.name)
16
 
 
 
 
17
  # Get the first page
18
  first_page = pdf_document[0]
19
 
@@ -24,18 +27,18 @@ def convert_pdf_to_image(pdf_file):
24
  img_data = pix.tobytes("png")
25
  img = Image.open(io.BytesIO(img_data))
26
 
27
- # Close the PDF document
28
- pdf_document.close()
29
-
30
  # Get PDF info
31
  pdf_info = f"""
32
  **PDF Conversion Results:**
33
- - Total pages: {len(pdf_document)}
34
  - First page converted to image
35
  - Image size: {img.width} x {img.height} pixels
36
  - Format: PNG
37
  """
38
 
 
 
 
39
  return pdf_info, img
40
 
41
  except Exception as e:
 
14
  # Open the PDF file
15
  pdf_document = fitz.open(pdf_file.name)
16
 
17
+ # Get PDF info before closing
18
+ total_pages = len(pdf_document)
19
+
20
  # Get the first page
21
  first_page = pdf_document[0]
22
 
 
27
  img_data = pix.tobytes("png")
28
  img = Image.open(io.BytesIO(img_data))
29
 
 
 
 
30
  # Get PDF info
31
  pdf_info = f"""
32
  **PDF Conversion Results:**
33
+ - Total pages: {total_pages}
34
  - First page converted to image
35
  - Image size: {img.width} x {img.height} pixels
36
  - Format: PNG
37
  """
38
 
39
+ # Close the PDF document
40
+ pdf_document.close()
41
+
42
  return pdf_info, img
43
 
44
  except Exception as e: