Update app.py
Browse files
app.py
CHANGED
|
@@ -84,6 +84,11 @@ def highlight_visual_changes(orig_img, edit_img, mask, start_position):
|
|
| 84 |
|
| 85 |
return overlay, visual_changes, position_counter
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
# Generate separate PDFs for visual and text changes
|
| 88 |
def generate_separate_pdfs(original_pdf, edited_pdf):
|
| 89 |
original_images = convert_pdf_to_images(original_pdf)
|
|
@@ -122,10 +127,10 @@ def generate_separate_pdfs(original_pdf, edited_pdf):
|
|
| 122 |
os.remove(temp_path)
|
| 123 |
pdf_visual.add_page()
|
| 124 |
pdf_visual.set_font("Arial", size=12)
|
| 125 |
-
pdf_visual.cell(0, 10, "Visual Changes", ln=True, align="C")
|
| 126 |
pdf_visual.ln(10)
|
| 127 |
for _, change in visual_changes:
|
| 128 |
-
pdf_visual.cell(0, 10, change, ln=True)
|
| 129 |
pdf_visual.output(visual_pdf_path)
|
| 130 |
|
| 131 |
# Generate Text Changes PDF
|
|
@@ -139,10 +144,10 @@ def generate_separate_pdfs(original_pdf, edited_pdf):
|
|
| 139 |
os.remove(temp_path)
|
| 140 |
pdf_text.add_page()
|
| 141 |
pdf_text.set_font("Arial", size=12)
|
| 142 |
-
pdf_text.cell(0, 10, "Text Changes", ln=True, align="C")
|
| 143 |
pdf_text.ln(10)
|
| 144 |
for _, change in text_changes:
|
| 145 |
-
pdf_text.cell(0, 10, change, ln=True)
|
| 146 |
pdf_text.output(text_pdf_path)
|
| 147 |
|
| 148 |
return visual_pdf_path, text_pdf_path
|
|
|
|
| 84 |
|
| 85 |
return overlay, visual_changes, position_counter
|
| 86 |
|
| 87 |
+
# Sanitize text for PDF compatibility
|
| 88 |
+
def sanitize_text(text):
|
| 89 |
+
"""Sanitize text for FPDF by replacing unsupported characters."""
|
| 90 |
+
return text.encode('latin-1', errors='replace').decode('latin-1')
|
| 91 |
+
|
| 92 |
# Generate separate PDFs for visual and text changes
|
| 93 |
def generate_separate_pdfs(original_pdf, edited_pdf):
|
| 94 |
original_images = convert_pdf_to_images(original_pdf)
|
|
|
|
| 127 |
os.remove(temp_path)
|
| 128 |
pdf_visual.add_page()
|
| 129 |
pdf_visual.set_font("Arial", size=12)
|
| 130 |
+
pdf_visual.cell(0, 10, sanitize_text("Visual Changes"), ln=True, align="C")
|
| 131 |
pdf_visual.ln(10)
|
| 132 |
for _, change in visual_changes:
|
| 133 |
+
pdf_visual.cell(0, 10, sanitize_text(change), ln=True)
|
| 134 |
pdf_visual.output(visual_pdf_path)
|
| 135 |
|
| 136 |
# Generate Text Changes PDF
|
|
|
|
| 144 |
os.remove(temp_path)
|
| 145 |
pdf_text.add_page()
|
| 146 |
pdf_text.set_font("Arial", size=12)
|
| 147 |
+
pdf_text.cell(0, 10, sanitize_text("Text Changes"), ln=True, align="C")
|
| 148 |
pdf_text.ln(10)
|
| 149 |
for _, change in text_changes:
|
| 150 |
+
pdf_text.cell(0, 10, sanitize_text(change), ln=True)
|
| 151 |
pdf_text.output(text_pdf_path)
|
| 152 |
|
| 153 |
return visual_pdf_path, text_pdf_path
|