Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +6 -6
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -279,8 +279,8 @@ if uploaded_file is not None:
|
|
| 279 |
|
| 280 |
# 2. Run pdftocgen -> raw.toc
|
| 281 |
status.write("Running pdftocgen (Scanning)...")
|
| 282 |
-
cmd1 =
|
| 283 |
-
process = subprocess.run(cmd1,
|
| 284 |
if process.returncode != 0:
|
| 285 |
st.error(f"pdftocgen failed: {process.stderr}")
|
| 286 |
st.stop()
|
|
@@ -291,8 +291,8 @@ if uploaded_file is not None:
|
|
| 291 |
# Existing Bookmarks
|
| 292 |
status.write("Extracting existing bookmarks...")
|
| 293 |
# Run pdftocio in extract mode
|
| 294 |
-
cmd1 =
|
| 295 |
-
process = subprocess.run(cmd1,
|
| 296 |
if process.returncode != 0:
|
| 297 |
st.error(f"pdftocio failed: {process.stderr}")
|
| 298 |
st.stop()
|
|
@@ -312,8 +312,8 @@ if uploaded_file is not None:
|
|
| 312 |
|
| 313 |
# 4. Write PDF
|
| 314 |
status.write("Writing to PDF...")
|
| 315 |
-
cmd3 =
|
| 316 |
-
process = subprocess.run(cmd3,
|
| 317 |
if process.returncode != 0:
|
| 318 |
st.error(f"pdftocio failed: {process.stderr}")
|
| 319 |
st.stop()
|
|
|
|
| 279 |
|
| 280 |
# 2. Run pdftocgen -> raw.toc
|
| 281 |
status.write("Running pdftocgen (Scanning)...")
|
| 282 |
+
cmd1 = [sys.executable, "-m", "pdftocgen", "-r", recipe_path, input_pdf_path]
|
| 283 |
+
process = subprocess.run(cmd1, capture_output=True, text=True, encoding='utf-8')
|
| 284 |
if process.returncode != 0:
|
| 285 |
st.error(f"pdftocgen failed: {process.stderr}")
|
| 286 |
st.stop()
|
|
|
|
| 291 |
# Existing Bookmarks
|
| 292 |
status.write("Extracting existing bookmarks...")
|
| 293 |
# Run pdftocio in extract mode
|
| 294 |
+
cmd1 = [sys.executable, "-m", "pdftocio", input_pdf_path]
|
| 295 |
+
process = subprocess.run(cmd1, capture_output=True, text=True, encoding='utf-8')
|
| 296 |
if process.returncode != 0:
|
| 297 |
st.error(f"pdftocio failed: {process.stderr}")
|
| 298 |
st.stop()
|
|
|
|
| 312 |
|
| 313 |
# 4. Write PDF
|
| 314 |
status.write("Writing to PDF...")
|
| 315 |
+
cmd3 = [sys.executable, "-m", "pdftocio", "-t", clean_toc_path, "-o", output_pdf_path, input_pdf_path]
|
| 316 |
+
process = subprocess.run(cmd3, capture_output=True, text=True)
|
| 317 |
if process.returncode != 0:
|
| 318 |
st.error(f"pdftocio failed: {process.stderr}")
|
| 319 |
st.stop()
|
requirements.txt
CHANGED
|
@@ -3,4 +3,4 @@ pandas
|
|
| 3 |
PyMuPDF==1.25.2
|
| 4 |
toml
|
| 5 |
chardet
|
| 6 |
-
|
|
|
|
| 3 |
PyMuPDF==1.25.2
|
| 4 |
toml
|
| 5 |
chardet
|
| 6 |
+
chardet
|