io4it 2.1.0.2__tar.gz → 2.1.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {io4it-2.1.0.2 → io4it-2.1.0.3}/PKG-INFO +1 -1
- {io4it-2.1.0.2 → io4it-2.1.0.3}/io4it.egg-info/PKG-INFO +1 -1
- io4it-2.1.0.3/io4it.egg-info/SOURCES.txt +9 -0
- {io4it-2.1.0.2 → io4it-2.1.0.3}/setup.py +1 -1
- io4it-2.1.0.2/io4it.egg-info/SOURCES.txt +0 -55
- io4it-2.1.0.2/orangecontrib/IO4IT/__init__.py +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/ocr_function/__init__.py +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/ocr_function/word_converter.py +0 -333
- io4it-2.1.0.2/orangecontrib/IO4IT/utils/__init__.py +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/utils/mail.py +0 -674
- io4it-2.1.0.2/orangecontrib/IO4IT/utils/offuscation_basique.py +0 -608
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/OWChatGpt.py +0 -201
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/OWDeep_Search.py +0 -217
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/OWExportMarkdown.py +0 -216
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/OWMarkdownizer.py +0 -652
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/OWS3Uploader.py +0 -106
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/OWS3downloader.py +0 -95
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/OWS3list.py +0 -113
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/OWSpeechToText.py +0 -364
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/OWmailLoader.py +0 -234
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/OWmailSender.py +0 -155
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/OWwordpdf2docx.py +0 -133
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/__init__.py +0 -19
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/designer/__init__.py +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/designer/chart.html +0 -281
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/designer/nogui.ui +0 -19
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/designer/ow_file_ext_selector.ui +0 -69
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/designer/owchatgpt.ui +0 -155
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/designer/owdeepsearch.ui +0 -74
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/designer/owexportmarkdown.ui +0 -51
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/designer/owmailloader.ui +0 -32
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/designer/owmailsender.ui +0 -32
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/designer/owmarkdownizer.ui +0 -101
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/designer/owspeechtotext.ui +0 -104
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/designer/owvisualizationer.ui +0 -56
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/designer/wordpdf2docx.ui +0 -57
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/icons/__init__.py +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/icons/chatgpt.png +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/icons/deepsearch.svg +0 -10
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/icons/download.png +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/icons/export_md.png +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/icons/file_extensor.png +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/icons/list_aws.png +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/icons/mail_loader.png +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/icons/mail_writer.png +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/icons/md.png +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/icons/speech_to_text.png +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/icons/upload.png +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/icons/visualizationer.png +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/icons/wordpdf2docx.png +0 -0
- io4it-2.1.0.2/orangecontrib/IO4IT/widgets/icons_dev/__init__.py +0 -0
- {io4it-2.1.0.2 → io4it-2.1.0.3}/io4it.egg-info/dependency_links.txt +0 -0
- {io4it-2.1.0.2 → io4it-2.1.0.3}/io4it.egg-info/entry_points.txt +0 -0
- {io4it-2.1.0.2 → io4it-2.1.0.3}/io4it.egg-info/namespace_packages.txt +0 -0
- {io4it-2.1.0.2 → io4it-2.1.0.3}/io4it.egg-info/requires.txt +0 -0
- {io4it-2.1.0.2 → io4it-2.1.0.3}/io4it.egg-info/top_level.txt +0 -0
- {io4it-2.1.0.2 → io4it-2.1.0.3}/orangecontrib/__init__.py +0 -0
- {io4it-2.1.0.2 → io4it-2.1.0.3}/setup.cfg +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
setup.py
|
|
2
|
+
io4it.egg-info/PKG-INFO
|
|
3
|
+
io4it.egg-info/SOURCES.txt
|
|
4
|
+
io4it.egg-info/dependency_links.txt
|
|
5
|
+
io4it.egg-info/entry_points.txt
|
|
6
|
+
io4it.egg-info/namespace_packages.txt
|
|
7
|
+
io4it.egg-info/requires.txt
|
|
8
|
+
io4it.egg-info/top_level.txt
|
|
9
|
+
orangecontrib/__init__.py
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
setup.py
|
|
2
|
-
io4it.egg-info/PKG-INFO
|
|
3
|
-
io4it.egg-info/SOURCES.txt
|
|
4
|
-
io4it.egg-info/dependency_links.txt
|
|
5
|
-
io4it.egg-info/entry_points.txt
|
|
6
|
-
io4it.egg-info/namespace_packages.txt
|
|
7
|
-
io4it.egg-info/requires.txt
|
|
8
|
-
io4it.egg-info/top_level.txt
|
|
9
|
-
orangecontrib/__init__.py
|
|
10
|
-
orangecontrib/IO4IT/__init__.py
|
|
11
|
-
orangecontrib/IO4IT/ocr_function/__init__.py
|
|
12
|
-
orangecontrib/IO4IT/ocr_function/word_converter.py
|
|
13
|
-
orangecontrib/IO4IT/utils/__init__.py
|
|
14
|
-
orangecontrib/IO4IT/utils/mail.py
|
|
15
|
-
orangecontrib/IO4IT/utils/offuscation_basique.py
|
|
16
|
-
orangecontrib/IO4IT/widgets/OWChatGpt.py
|
|
17
|
-
orangecontrib/IO4IT/widgets/OWDeep_Search.py
|
|
18
|
-
orangecontrib/IO4IT/widgets/OWExportMarkdown.py
|
|
19
|
-
orangecontrib/IO4IT/widgets/OWMarkdownizer.py
|
|
20
|
-
orangecontrib/IO4IT/widgets/OWS3Uploader.py
|
|
21
|
-
orangecontrib/IO4IT/widgets/OWS3downloader.py
|
|
22
|
-
orangecontrib/IO4IT/widgets/OWS3list.py
|
|
23
|
-
orangecontrib/IO4IT/widgets/OWSpeechToText.py
|
|
24
|
-
orangecontrib/IO4IT/widgets/OWmailLoader.py
|
|
25
|
-
orangecontrib/IO4IT/widgets/OWmailSender.py
|
|
26
|
-
orangecontrib/IO4IT/widgets/OWwordpdf2docx.py
|
|
27
|
-
orangecontrib/IO4IT/widgets/__init__.py
|
|
28
|
-
orangecontrib/IO4IT/widgets/designer/__init__.py
|
|
29
|
-
orangecontrib/IO4IT/widgets/designer/chart.html
|
|
30
|
-
orangecontrib/IO4IT/widgets/designer/nogui.ui
|
|
31
|
-
orangecontrib/IO4IT/widgets/designer/ow_file_ext_selector.ui
|
|
32
|
-
orangecontrib/IO4IT/widgets/designer/owchatgpt.ui
|
|
33
|
-
orangecontrib/IO4IT/widgets/designer/owdeepsearch.ui
|
|
34
|
-
orangecontrib/IO4IT/widgets/designer/owexportmarkdown.ui
|
|
35
|
-
orangecontrib/IO4IT/widgets/designer/owmailloader.ui
|
|
36
|
-
orangecontrib/IO4IT/widgets/designer/owmailsender.ui
|
|
37
|
-
orangecontrib/IO4IT/widgets/designer/owmarkdownizer.ui
|
|
38
|
-
orangecontrib/IO4IT/widgets/designer/owspeechtotext.ui
|
|
39
|
-
orangecontrib/IO4IT/widgets/designer/owvisualizationer.ui
|
|
40
|
-
orangecontrib/IO4IT/widgets/designer/wordpdf2docx.ui
|
|
41
|
-
orangecontrib/IO4IT/widgets/icons/__init__.py
|
|
42
|
-
orangecontrib/IO4IT/widgets/icons/chatgpt.png
|
|
43
|
-
orangecontrib/IO4IT/widgets/icons/deepsearch.svg
|
|
44
|
-
orangecontrib/IO4IT/widgets/icons/download.png
|
|
45
|
-
orangecontrib/IO4IT/widgets/icons/export_md.png
|
|
46
|
-
orangecontrib/IO4IT/widgets/icons/file_extensor.png
|
|
47
|
-
orangecontrib/IO4IT/widgets/icons/list_aws.png
|
|
48
|
-
orangecontrib/IO4IT/widgets/icons/mail_loader.png
|
|
49
|
-
orangecontrib/IO4IT/widgets/icons/mail_writer.png
|
|
50
|
-
orangecontrib/IO4IT/widgets/icons/md.png
|
|
51
|
-
orangecontrib/IO4IT/widgets/icons/speech_to_text.png
|
|
52
|
-
orangecontrib/IO4IT/widgets/icons/upload.png
|
|
53
|
-
orangecontrib/IO4IT/widgets/icons/visualizationer.png
|
|
54
|
-
orangecontrib/IO4IT/widgets/icons/wordpdf2docx.png
|
|
55
|
-
orangecontrib/IO4IT/widgets/icons_dev/__init__.py
|
|
File without changes
|
|
File without changes
|
|
@@ -1,333 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import win32com.client
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
import pathlib
|
|
5
|
-
import shutil
|
|
6
|
-
import time
|
|
7
|
-
import pythoncom
|
|
8
|
-
import fitz
|
|
9
|
-
|
|
10
|
-
if "site-packages/Orange/widgets" in os.path.dirname(os.path.abspath(__file__)).replace("\\", "/"):
|
|
11
|
-
from Orange.widgets.orangecontrib.AAIT.utils.MetManagement import get_local_store_path,reset_folder
|
|
12
|
-
else:
|
|
13
|
-
from orangecontrib.AAIT.utils.MetManagement import get_local_store_path,reset_folder
|
|
14
|
-
|
|
15
|
-
def enable_long_path(path):
|
|
16
|
-
"""Simplifie la gestion des chemins longs sous Windows."""
|
|
17
|
-
return pathlib.Path(r"\\?\\" + str(path))
|
|
18
|
-
|
|
19
|
-
def convert_pdf_structure(input_dir: str, output_dir: str,ignore_exsting_out_put=False,progress_callback=None):
|
|
20
|
-
"""
|
|
21
|
-
return a string with log in case of error
|
|
22
|
-
Recursively lists all .pdf and .PDF files in the input directory,
|
|
23
|
-
replicates the folder structure in the output directory, and
|
|
24
|
-
creates empty .docx files with the same names.
|
|
25
|
-
|
|
26
|
-
Parameters:
|
|
27
|
-
input_dir (str): Path to the input directory containing PDF files.
|
|
28
|
-
output_dir (str): Path to the output directory where DOCX files will be created.
|
|
29
|
-
"""
|
|
30
|
-
error_log=""
|
|
31
|
-
if os.name != 'nt':
|
|
32
|
-
error_log="version developped for windows computer "
|
|
33
|
-
return error_log
|
|
34
|
-
|
|
35
|
-
nbre_file = 0
|
|
36
|
-
for i, data in enumerate(input_dir):
|
|
37
|
-
input_path = Path(str(input_dir[i]))
|
|
38
|
-
for pdf_file in input_path.rglob("*.pdf"):
|
|
39
|
-
nbre_file += 1
|
|
40
|
-
|
|
41
|
-
k = 1
|
|
42
|
-
for i, data in enumerate(input_dir):
|
|
43
|
-
input_path = Path(str(input_dir[i]))
|
|
44
|
-
output_path = Path(str(output_dir[i]))
|
|
45
|
-
|
|
46
|
-
if not input_path.exists() or not input_path.is_dir():
|
|
47
|
-
print(f"Error: The input directory '{input_dir}' does not exist or is not a directory.")
|
|
48
|
-
return f"Error: The input directory '{input_dir}' does not exist or is not a directory. "
|
|
49
|
-
|
|
50
|
-
for pdf_file in input_path.rglob("*.pdf"): # Recursively search for .pdf and .PDF files
|
|
51
|
-
print("traitement de ",str(pdf_file))
|
|
52
|
-
relative_path = pdf_file.relative_to(input_path) # Get relative path from input root
|
|
53
|
-
new_file_path = output_path / relative_path.with_suffix(".docx") # Change extension to .docx
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if ignore_exsting_out_put:
|
|
58
|
-
if os.path.exists(enable_long_path(str(new_file_path))):
|
|
59
|
-
print("ignoring",enable_long_path(str(new_file_path)))
|
|
60
|
-
continue
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if 0!= convert_pdf_with_temp(str(pdf_file),str(new_file_path)):#convert_pdf_with_temp #convert_pdf_to_docx
|
|
64
|
-
if error_log!="":
|
|
65
|
-
error_log+="\n"
|
|
66
|
-
error_log+="error -> "+str(pdf_file)
|
|
67
|
-
return error_log # a supprimer
|
|
68
|
-
if progress_callback is not None:
|
|
69
|
-
progress_value = float(100 * (k) / nbre_file)
|
|
70
|
-
k += 1
|
|
71
|
-
progress_callback(progress_value)
|
|
72
|
-
# purge temp dir if everithing is ok
|
|
73
|
-
if error_log=="":
|
|
74
|
-
reset_folder(get_local_store_path() + "temp_word_conversion/", attempts=10, delay=0.05, recreate=False)
|
|
75
|
-
return error_log
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def convert_pdf_to_docx(pdf_path, docx_path):
|
|
81
|
-
"""
|
|
82
|
-
Convertit un fichier PDF en DOCX en utilisant Microsoft Word.
|
|
83
|
-
|
|
84
|
-
Args:
|
|
85
|
-
pdf_path (str): Chemin du fichier PDF source.
|
|
86
|
-
docx_path (str): Chemin du fichier DOCX de destination.
|
|
87
|
-
|
|
88
|
-
Returns:
|
|
89
|
-
int: 0 si la conversion a réussi, 1 en cas d'échec.
|
|
90
|
-
"""
|
|
91
|
-
if not os.path.exists(pdf_path):
|
|
92
|
-
print(f"Erreur : Le fichier {pdf_path} n'existe pas.")
|
|
93
|
-
return 1
|
|
94
|
-
|
|
95
|
-
try:
|
|
96
|
-
# Initialiser COM
|
|
97
|
-
pythoncom.CoInitialize()
|
|
98
|
-
|
|
99
|
-
# Lancer Word
|
|
100
|
-
word = win32com.client.Dispatch("Word.Application")
|
|
101
|
-
word.DisplayAlerts = 0 # Désactiver les alertes
|
|
102
|
-
word.Visible = True # Mettre à True pour voir Word en action
|
|
103
|
-
print(f"Conversion de {pdf_path} en {docx_path}...")
|
|
104
|
-
|
|
105
|
-
# Ouvrir le PDF en lecture seule
|
|
106
|
-
doc = word.Documents.Open(pdf_path, ReadOnly=True, ConfirmConversions=False)
|
|
107
|
-
|
|
108
|
-
# Sauvegarder en DOCX
|
|
109
|
-
doc.SaveAs(docx_path, FileFormat=16) # 16 = wdFormatDocumentDefault
|
|
110
|
-
doc.Close(False)
|
|
111
|
-
|
|
112
|
-
print(f"Conversion réussie : {docx_path}")
|
|
113
|
-
return 0
|
|
114
|
-
|
|
115
|
-
except Exception as e:
|
|
116
|
-
print(f"Erreur lors de la conversion : {e}")
|
|
117
|
-
return 1
|
|
118
|
-
|
|
119
|
-
finally:
|
|
120
|
-
if 'word' in locals():
|
|
121
|
-
word.Quit()
|
|
122
|
-
|
|
123
|
-
# Libérer COM
|
|
124
|
-
pythoncom.CoUninitialize()
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
def wait_for_file_access(file_path, timeout=10, interval=0.5):
|
|
128
|
-
"""
|
|
129
|
-
Attendre que le fichier soit accessible en lecture/écriture.
|
|
130
|
-
|
|
131
|
-
Args:
|
|
132
|
-
file_path (str): Chemin du fichier à vérifier.
|
|
133
|
-
timeout (int): Temps max en secondes avant d'abandonner.
|
|
134
|
-
interval (float): Temps d'attente entre chaque vérification.
|
|
135
|
-
|
|
136
|
-
Returns:
|
|
137
|
-
bool: True si le fichier est accessible, False sinon.
|
|
138
|
-
"""
|
|
139
|
-
start_time = time.time()
|
|
140
|
-
|
|
141
|
-
while time.time() - start_time < timeout:
|
|
142
|
-
if os.path.exists(file_path) and os.access(file_path, os.R_OK | os.W_OK):
|
|
143
|
-
try:
|
|
144
|
-
with open(file_path, "a"):
|
|
145
|
-
pass # Test d'ouverture en écriture
|
|
146
|
-
return True
|
|
147
|
-
except IOError:
|
|
148
|
-
pass
|
|
149
|
-
|
|
150
|
-
time.sleep(interval) # Attendre avant de réessayer
|
|
151
|
-
|
|
152
|
-
print(f"Erreur : Le fichier {file_path} est verrouillé ou inaccessible.")
|
|
153
|
-
return False
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
def is_pdf_a4(pdf_path: str) -> bool:
|
|
159
|
-
"""
|
|
160
|
-
Vérifie si toutes les pages du PDF sont au format A4.
|
|
161
|
-
Retourne True si toutes les pages sont en A4, False sinon.
|
|
162
|
-
"""
|
|
163
|
-
A4_WIDTH_PTS = 595 # Largeur A4 en points (approx. 210mm)
|
|
164
|
-
A4_HEIGHT_PTS = 842 # Hauteur A4 en points (approx. 297mm)
|
|
165
|
-
TOLERANCE = 5 # Marge de tolérance en points
|
|
166
|
-
|
|
167
|
-
try:
|
|
168
|
-
doc = fitz.open(pdf_path)
|
|
169
|
-
if len(doc) == 0:
|
|
170
|
-
return False
|
|
171
|
-
|
|
172
|
-
for page in doc:
|
|
173
|
-
width, height = page.rect.width, page.rect.height
|
|
174
|
-
if not (
|
|
175
|
-
(abs(width - A4_WIDTH_PTS) <= TOLERANCE and abs(height - A4_HEIGHT_PTS) <= TOLERANCE) or
|
|
176
|
-
(abs(width - A4_HEIGHT_PTS) <= TOLERANCE and abs(height - A4_WIDTH_PTS) <= TOLERANCE)
|
|
177
|
-
):
|
|
178
|
-
return False
|
|
179
|
-
except Exception as e:
|
|
180
|
-
print("is A4?",e)
|
|
181
|
-
return False
|
|
182
|
-
return True
|
|
183
|
-
|
|
184
|
-
def convert_pdf_to_a4(input_pdf, output_pdf):
|
|
185
|
-
try:
|
|
186
|
-
# Dimensions A4 en points
|
|
187
|
-
a4_width, a4_height = fitz.paper_size("a4")
|
|
188
|
-
a3_width, a3_height = fitz.paper_size("a3")
|
|
189
|
-
doc = fitz.open(input_pdf)
|
|
190
|
-
new_doc = fitz.open()
|
|
191
|
-
|
|
192
|
-
for page in doc:
|
|
193
|
-
page_w, page_h = page.rect.width, page.rect.height
|
|
194
|
-
|
|
195
|
-
# Si la page est déjà en A4 (tolérance de 1 point)
|
|
196
|
-
if abs(page_w - a4_width) < 1 and abs(page_h - a4_height) < 1:
|
|
197
|
-
new_doc.insert_pdf(doc, from_page=page.number, to_page=page.number)
|
|
198
|
-
continue
|
|
199
|
-
|
|
200
|
-
# Si la page est déjà en A3 (tolérance de 1 point)
|
|
201
|
-
if abs(page_w - a3_width) < 1 and abs(page_h - a3_height) < 1:
|
|
202
|
-
new_doc.insert_pdf(doc, from_page=page.number, to_page=page.number)
|
|
203
|
-
continue
|
|
204
|
-
|
|
205
|
-
# Définition de la transformation selon l'orientation de la page
|
|
206
|
-
if page_w > page_h: # Paysage
|
|
207
|
-
# Après rotation, les dimensions seront inversées (largeur <-> hauteur)
|
|
208
|
-
effective_scale = min(a4_width / page_h, a4_height / page_w)
|
|
209
|
-
matrix = fitz.Matrix(effective_scale, effective_scale)
|
|
210
|
-
# Rotation de 90° et translation pour repositionner le contenu
|
|
211
|
-
matrix = matrix.prerotate(90).pretranslate(page_h * effective_scale, 0)
|
|
212
|
-
else: # Portrait
|
|
213
|
-
effective_scale = min(a4_width / page_w, a4_height / page_h)
|
|
214
|
-
matrix = fitz.Matrix(effective_scale, effective_scale)
|
|
215
|
-
|
|
216
|
-
# Générer le pixmap à la résolution finale souhaitée
|
|
217
|
-
pix = page.get_pixmap(matrix=matrix)
|
|
218
|
-
|
|
219
|
-
# Calcul du centrage sur la page A4
|
|
220
|
-
new_img_w, new_img_h = pix.width, pix.height
|
|
221
|
-
x_offset = (a4_width - new_img_w) / 2
|
|
222
|
-
y_offset = (a4_height - new_img_h) / 2
|
|
223
|
-
|
|
224
|
-
# Créer la nouvelle page et y insérer l'image
|
|
225
|
-
new_page = new_doc.new_page(width=a4_width, height=a4_height)
|
|
226
|
-
new_page.insert_image(
|
|
227
|
-
fitz.Rect(x_offset, y_offset, x_offset + new_img_w, y_offset + new_img_h),
|
|
228
|
-
pixmap=pix
|
|
229
|
-
)
|
|
230
|
-
new_doc.save(output_pdf)
|
|
231
|
-
new_doc.close()
|
|
232
|
-
doc.close()
|
|
233
|
-
return 0
|
|
234
|
-
except:
|
|
235
|
-
return 1
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
def write_two_strings_to_file(file_path: str,string1: str, string2: str):
|
|
239
|
-
"""
|
|
240
|
-
Writes two strings to a file, one per line, handling errors gracefully.
|
|
241
|
-
|
|
242
|
-
:param string1: The first string to write.
|
|
243
|
-
:param string2: The second string to write.
|
|
244
|
-
:param file_path: The path where the file should be saved.
|
|
245
|
-
"""
|
|
246
|
-
try:
|
|
247
|
-
file = open(file_path, 'w', encoding='utf-8')
|
|
248
|
-
file.write(string1 + "\n")
|
|
249
|
-
file.write(string2 )
|
|
250
|
-
print(f"Successfully written to {file_path}")
|
|
251
|
-
except IOError as e:
|
|
252
|
-
print(f"Error writing to file: {e}")
|
|
253
|
-
return 1
|
|
254
|
-
except Exception as e:
|
|
255
|
-
print(f"An unexpected error occurred: {e}")
|
|
256
|
-
return 1
|
|
257
|
-
finally:
|
|
258
|
-
file.close()
|
|
259
|
-
return 0
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
def convert_pdf_with_temp(temp_pdf, output_path):
|
|
263
|
-
"""
|
|
264
|
-
Copie le PDF source dans un dossier temporaire, le convertit en DOCX,
|
|
265
|
-
puis copie le fichier résultant vers le chemin de sortie spécifié,
|
|
266
|
-
en gérant les chemins longs.
|
|
267
|
-
"""
|
|
268
|
-
pdf_path = enable_long_path(os.path.abspath(temp_pdf))
|
|
269
|
-
output_path = enable_long_path(os.path.abspath(output_path))
|
|
270
|
-
output_dir = output_path.parent
|
|
271
|
-
|
|
272
|
-
if not pdf_path.exists():
|
|
273
|
-
print(f"Le fichier {pdf_path} n'existe pas.")
|
|
274
|
-
return 1
|
|
275
|
-
|
|
276
|
-
# Créer le dossier de sortie s'il n'existe pas
|
|
277
|
-
if not output_dir.exists():
|
|
278
|
-
output_dir.mkdir(parents=True, exist_ok=True)
|
|
279
|
-
|
|
280
|
-
try:
|
|
281
|
-
dest_dir = get_local_store_path() + "temp_word_conversion/"
|
|
282
|
-
if 0 != reset_folder(dest_dir, attempts=10, delay=0.05):
|
|
283
|
-
print("impossible to reset " + dest_dir)
|
|
284
|
-
return 1
|
|
285
|
-
# Création du dossier temporaire
|
|
286
|
-
temp_pdf = os.path.join(dest_dir, "input_toto.pdf")
|
|
287
|
-
temp_docx = os.path.join(dest_dir, "input_toto.docx")
|
|
288
|
-
|
|
289
|
-
print(dest_dir+"conversion_en_cours.txt")
|
|
290
|
-
print("######################################")
|
|
291
|
-
if 0!=write_two_strings_to_file(dest_dir+"conversion_en_cours.txt",str(pdf_path),str(output_path)):
|
|
292
|
-
print("error writing ",dest_dir+"conversion_en_cours.txt")
|
|
293
|
-
return 1
|
|
294
|
-
# Copie du fichier source vers le dossier temporaire
|
|
295
|
-
shutil.copy2(pdf_path, temp_pdf)
|
|
296
|
-
wait_for_file_access(temp_pdf)
|
|
297
|
-
|
|
298
|
-
if is_pdf_a4(temp_pdf)==False:
|
|
299
|
-
temp_pdf2 = os.path.join(dest_dir, "input_totoA4.pdf")
|
|
300
|
-
if 0!=convert_pdf_to_a4(temp_pdf,temp_pdf2):
|
|
301
|
-
print("erreur au resize du pdf")
|
|
302
|
-
return 1
|
|
303
|
-
temp_pdf=temp_pdf2
|
|
304
|
-
wait_for_file_access(temp_pdf)
|
|
305
|
-
time.sleep(1)
|
|
306
|
-
result=0
|
|
307
|
-
# Conversion du PDF en DOCX
|
|
308
|
-
for _ in range(4):
|
|
309
|
-
time.sleep(1)
|
|
310
|
-
result = convert_pdf_to_docx(str(temp_pdf), str(temp_docx))
|
|
311
|
-
if result==0:
|
|
312
|
-
break
|
|
313
|
-
if result == 0:
|
|
314
|
-
# Copie du fichier converti vers la destination finale
|
|
315
|
-
shutil.copy2(temp_docx, output_path)
|
|
316
|
-
print(f"recopie réussie : {output_path}")
|
|
317
|
-
|
|
318
|
-
# Supprimer les fichiers temporaires après le déplacement
|
|
319
|
-
# if temp_docx.exists():
|
|
320
|
-
# temp_docx.unlink()
|
|
321
|
-
# if temp_pdf.exists():
|
|
322
|
-
# temp_pdf.unlink()
|
|
323
|
-
return 0
|
|
324
|
-
else:
|
|
325
|
-
print("Erreur lors de la conversion.")
|
|
326
|
-
return 1
|
|
327
|
-
|
|
328
|
-
except Exception as e:
|
|
329
|
-
print(f"Erreur : {e}")
|
|
330
|
-
return 1
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
File without changes
|