rehan953 commited on
Commit
d9d6fe1
·
verified ·
1 Parent(s): 97234d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -6
app.py CHANGED
@@ -2215,13 +2215,33 @@ def _parse_nfcu_page(pdf_path: str, page_num: int) -> str:
2215
  Returns complete HTML string for the page, or "" if not NFCU / any error.
2216
  """
2217
  try:
2218
- import pdfplumber
2219
-
2220
- with pdfplumber.open(pdf_path) as pdf:
2221
- if page_num >= len(pdf.pages):
 
 
 
 
 
2222
  return ""
2223
- page = pdf.pages[page_num]
2224
- text = page.extract_text() or ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2225
 
2226
  if not text:
2227
  return ""
 
2215
  Returns complete HTML string for the page, or "" if not NFCU / any error.
2216
  """
2217
  try:
2218
+ # Extract full page text using pymupdf (installed on HuggingFace) or
2219
+ # pdfplumber (installed locally) — try both so the function works in
2220
+ # either environment.
2221
+ text = ""
2222
+ try:
2223
+ import pymupdf as _fitz_nf
2224
+ _doc_nf = _fitz_nf.open(pdf_path)
2225
+ if page_num >= len(_doc_nf):
2226
+ _doc_nf.close()
2227
  return ""
2228
+ text = _doc_nf[page_num].get_text() or ""
2229
+ _doc_nf.close()
2230
+ except Exception:
2231
+ pass
2232
+
2233
+ if not text:
2234
+ try:
2235
+ import pdfplumber as _plumber_nf
2236
+ with _plumber_nf.open(pdf_path) as _pdf_nf:
2237
+ if page_num >= len(_pdf_nf.pages):
2238
+ return ""
2239
+ text = _pdf_nf.pages[page_num].extract_text() or ""
2240
+ except Exception:
2241
+ pass
2242
+
2243
+ if not text:
2244
+ return ""
2245
 
2246
  if not text:
2247
  return ""