Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,9 @@ PAGE_WIDTH, PAGE_HEIGHT = letter
|
|
| 9 |
|
| 10 |
def generate_pdf(file):
|
| 11 |
try:
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
except Exception as e:
|
| 14 |
return None, f"Error reading JSON: {e}"
|
| 15 |
|
|
@@ -31,6 +33,7 @@ def generate_pdf(file):
|
|
| 31 |
box_height = y2 - y1
|
| 32 |
font_size = max(6, min(18, box_height * 0.8))
|
| 33 |
|
|
|
|
| 34 |
c.setStrokeColor(colors.lightgrey)
|
| 35 |
c.rect(x1, PAGE_HEIGHT - y2, x2 - x1, box_height, fill=0)
|
| 36 |
|
|
@@ -46,6 +49,7 @@ def generate_pdf(file):
|
|
| 46 |
if page_created:
|
| 47 |
c.showPage()
|
| 48 |
|
|
|
|
| 49 |
if not page_created:
|
| 50 |
c.setFont("Helvetica", 12)
|
| 51 |
c.drawString(50, 750, "No OCR text found")
|
|
|
|
| 9 |
|
| 10 |
def generate_pdf(file):
|
| 11 |
try:
|
| 12 |
+
# Open the uploaded file safely
|
| 13 |
+
with open(file.name, "r", encoding="utf-8") as f:
|
| 14 |
+
data = json.load(f)
|
| 15 |
except Exception as e:
|
| 16 |
return None, f"Error reading JSON: {e}"
|
| 17 |
|
|
|
|
| 33 |
box_height = y2 - y1
|
| 34 |
font_size = max(6, min(18, box_height * 0.8))
|
| 35 |
|
| 36 |
+
# Draw bounding box (optional for debug)
|
| 37 |
c.setStrokeColor(colors.lightgrey)
|
| 38 |
c.rect(x1, PAGE_HEIGHT - y2, x2 - x1, box_height, fill=0)
|
| 39 |
|
|
|
|
| 49 |
if page_created:
|
| 50 |
c.showPage()
|
| 51 |
|
| 52 |
+
# Guarantee at least one page
|
| 53 |
if not page_created:
|
| 54 |
c.setFont("Helvetica", 12)
|
| 55 |
c.drawString(50, 750, "No OCR text found")
|