Fix PDF support and template URL issues
- Add PDF_SUPPORT checks before using PyMuPDF functions
- Handle missing PyMuPDF gracefully in PDF processing functions
- Fix url_for('jobs') to url_for('jobs_page') in templates
- Prevent AttributeError when fitz is None
This commit is contained in:
1 parent
12e46e3993
commit
25e4ccad07
3 files changed
+22
-5
No files matched your search
@@ -444,7 +444,7 @@ def get_job_status(job_id):
|
|||||||
"file_count": job.get("file_count", 0)
|
"file_count": job.get("file_count", 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
def process_pdfs(pdfdir, outputfolder):
|
def process_pdfs(pdfdir, outputfolder, job_id=None):
|
||||||
global processing_complete
|
global processing_complete
|
||||||
status_file = 'status.txt'
|
status_file = 'status.txt'
|
||||||
with open(status_file, 'w') as status_f:
|
with open(status_file, 'w') as status_f:
|
||||||
@@ -537,7 +537,8 @@ def process_pdfs(pdfdir, outputfolder):
|
|||||||
|
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
# Merge by page count
|
# Merge by page count (only if PDF support is available)
|
||||||
|
if PDF_SUPPORT:
|
||||||
page_groups = {}
|
page_groups = {}
|
||||||
for filepath in pdf_files:
|
for filepath in pdf_files:
|
||||||
f = os.path.basename(filepath)
|
f = os.path.basename(filepath)
|
||||||
@@ -579,6 +580,12 @@ def process_pdfs(pdfdir, outputfolder):
|
|||||||
status_f.write(msg)
|
status_f.write(msg)
|
||||||
print(msg.strip())
|
print(msg.strip())
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
|
else:
|
||||||
|
msg = "Step 3/4: PDF merging skipped (PyMuPDF not available)\n"
|
||||||
|
with open(status_file, 'a') as status_f:
|
||||||
|
status_f.write(msg)
|
||||||
|
print(msg.strip())
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
msg = f"Processing complete! Processed {len(pdf_files)} files total\n"
|
msg = f"Processing complete! Processed {len(pdf_files)} files total\n"
|
||||||
with open(status_file, 'a') as status_f:
|
with open(status_file, 'a') as status_f:
|
||||||
@@ -774,7 +781,8 @@ def process_pdfs_async(pdfdir, outputfolder, job_id):
|
|||||||
|
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
# Merge by page count
|
# Merge by page count (only if PDF support is available)
|
||||||
|
if PDF_SUPPORT:
|
||||||
msg = f"Step 3/4: Found {len(page_groups)} different page counts to merge\n"
|
msg = f"Step 3/4: Found {len(page_groups)} different page counts to merge\n"
|
||||||
with open(status_file, 'a') as status_f:
|
with open(status_file, 'a') as status_f:
|
||||||
status_f.write(msg)
|
status_f.write(msg)
|
||||||
@@ -806,6 +814,12 @@ def process_pdfs_async(pdfdir, outputfolder, job_id):
|
|||||||
status_f.write(msg)
|
status_f.write(msg)
|
||||||
print(msg.strip())
|
print(msg.strip())
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
|
else:
|
||||||
|
msg = "Step 3/4: PDF merging skipped (PyMuPDF not available)\n"
|
||||||
|
with open(status_file, 'a') as status_f:
|
||||||
|
status_f.write(msg)
|
||||||
|
print(msg.strip())
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
msg = f"Processing complete! Processed {len(pdf_files)} files total\n"
|
msg = f"Processing complete! Processed {len(pdf_files)} files total\n"
|
||||||
with open(status_file, 'a') as status_f:
|
with open(status_file, 'a') as status_f:
|
||||||
@@ -935,6 +949,9 @@ def clear_and_upload():
|
|||||||
|
|
||||||
def process_single_pdf(filepath):
|
def process_single_pdf(filepath):
|
||||||
"""Process a single PDF file and return the result."""
|
"""Process a single PDF file and return the result."""
|
||||||
|
if not PDF_SUPPORT:
|
||||||
|
return {'type': 'error', 'filename': os.path.basename(filepath), 'error': 'PDF processing not available (PyMuPDF not installed)', 'filepath': filepath}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f = os.path.basename(filepath)
|
f = os.path.basename(filepath)
|
||||||
doc = fitz.open(filepath)
|
doc = fitz.open(filepath)
|
||||||
|
|||||||
+1
-1
@@ -173,7 +173,7 @@
|
|||||||
<div class="nav-links">
|
<div class="nav-links">
|
||||||
<a href="{{ url_for('index') }}" class="nav-link">📤 Upload Files</a>
|
<a href="{{ url_for('index') }}" class="nav-link">📤 Upload Files</a>
|
||||||
<a href="{{ url_for('results') }}" class="nav-link">📋 View Results</a>
|
<a href="{{ url_for('results') }}" class="nav-link">📋 View Results</a>
|
||||||
<a href="{{ url_for('jobs') }}" class="nav-link">📊 View All Jobs</a>
|
<a href="{{ url_for('jobs_page') }}" class="nav-link">📊 View All Jobs</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<a href="{{ url_for('index') }}" class="back-link">← Back to Upload</a>
|
<a href="{{ url_for('index') }}" class="back-link">← Back to Upload</a>
|
||||||
|
|||||||
@@ -162,7 +162,7 @@
|
|||||||
<div class="nav-links">
|
<div class="nav-links">
|
||||||
<a href="{{ url_for('index') }}" class="nav-link">📤 Upload Files</a>
|
<a href="{{ url_for('index') }}" class="nav-link">📤 Upload Files</a>
|
||||||
<a href="{{ url_for('results') }}" class="nav-link">📋 View Results</a>
|
<a href="{{ url_for('results') }}" class="nav-link">📋 View Results</a>
|
||||||
<a href="{{ url_for('jobs') }}" class="nav-link">📊 View All Jobs</a>
|
<a href="{{ url_for('jobs_page') }}" class="nav-link">📊 View All Jobs</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<a href="{{ url_for('index') }}" class="back-link">← Back to Upload</a>
|
<a href="{{ url_for('index') }}" class="back-link">← Back to Upload</a>
|
||||||
|
|||||||
Reference in new issue
Block a user