Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,14 +34,11 @@ check_write_permission(OUTPUT_DIR)
|
|
| 34 |
# PDF轉圖片(使用 PyMuPDF)
|
| 35 |
def pdf_to_images(pdf_file):
|
| 36 |
try:
|
|
|
|
| 37 |
image_paths = []
|
| 38 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_pdf:
|
| 39 |
-
tmp_pdf.write(pdf_file.read())
|
| 40 |
-
tmp_pdf.flush()
|
| 41 |
-
doc = fitz.open(tmp_pdf.name)
|
| 42 |
|
| 43 |
for i, page in enumerate(doc, start=1):
|
| 44 |
-
pix = page.get_pixmap(matrix=fitz.Matrix(2, 2))
|
| 45 |
img_path = os.path.join(FG_DIR, f"page_{i:03d}.jpg")
|
| 46 |
pix.save(img_path)
|
| 47 |
image_paths.append(img_path)
|
|
|
|
| 34 |
# PDF轉圖片(使用 PyMuPDF)
|
| 35 |
def pdf_to_images(pdf_file):
|
| 36 |
try:
|
| 37 |
+
doc = fitz.open(pdf_file.name) # 直接使用暫存檔案路徑
|
| 38 |
image_paths = []
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
for i, page in enumerate(doc, start=1):
|
| 41 |
+
pix = page.get_pixmap(matrix=fitz.Matrix(2, 2))
|
| 42 |
img_path = os.path.join(FG_DIR, f"page_{i:03d}.jpg")
|
| 43 |
pix.save(img_path)
|
| 44 |
image_paths.append(img_path)
|