Skip to content

Commit 3555785

Browse files
committed
adds unblocking feature to unblock protected word files
1 parent e087123 commit 3555785

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

MergePDFGUI/MergePDFs.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@
33
import subprocess
44
import platform
55
import threading
6+
import traceback
7+
import win32com.client
68
from tkinter import Tk, Label, Button, filedialog, messagebox, StringVar, Frame
79
from docx2pdf import convert
810
from PyPDF2 import PdfMerger
911

1012
dot_count = 0
1113
running = False
1214

15+
def unblock_file(filepath):
16+
if os.name == 'nt':
17+
try:
18+
zone_file = filepath + ":Zone.Identifier"
19+
if os.path.exists(zone_file):
20+
os.remove(zone_file)
21+
except Exception as e:
22+
print(f"Failed to unblock {filepath}: {e}")
23+
24+
1325
def run_conversion(input_folder, output_folder):
1426
global running
1527
status_percent.config(text=f"0%")
@@ -30,13 +42,25 @@ def run_conversion(input_folder, output_folder):
3042
for i, file in enumerate(word_files, start=1):
3143
if file.lower().endswith(".docx"):
3244

33-
original_src = os.path.join(input_folder, file)
45+
unblock_file(os.path.join(input_folder, file))
46+
47+
original_src = os.path.abspath(os.path.join(input_folder, file))
3448
temp_dst = os.path.join(temp_word_dir, file)
3549
shutil.copy2(original_src, temp_dst)
3650

3751
pdf_path = os.path.join(temp_dir, file.replace(".docx", ".pdf"))
3852
try:
39-
convert(temp_dst, pdf_path)
53+
word_app = win32com.client.Dispatch("Word.Application")
54+
print("opening")
55+
doc = word_app.Documents.Open(original_src)
56+
print('opened')
57+
try:
58+
doc.ExportAsFixedFormat(pdf_path, 17)
59+
except Exception as e:
60+
print(f"Word export failed for {file}")
61+
print(e)
62+
traceback.print_exc()
63+
raise
4064
except Exception as e:
4165
messagebox.showerror("Error", f"Failed to convert {file}: {e}")
4266
continue

MergePDFGUI/MergePDFs.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ exe = EXE(
2929
upx=True,
3030
upx_exclude=[],
3131
runtime_tmpdir=None,
32-
console=False,
32+
console=True,
3333
disable_windowed_traceback=False,
3434
argv_emulation=False,
3535
target_arch=None,

0 commit comments

Comments
 (0)