|
@@ -1,29 +0,0 @@
|
|
|
-import os
|
|
|
|
|
-from docx import Document
|
|
|
|
|
-from PIL import ImageGrab
|
|
|
|
|
-
|
|
|
|
|
-def save_images(doc, folder_path):
|
|
|
|
|
- if not os.path.exists(folder_path):
|
|
|
|
|
- os.makedirs(folder_path)
|
|
|
|
|
-
|
|
|
|
|
- for index, paragraph in enumerate(doc.paragraphs):
|
|
|
|
|
- if paragraph.style.name.startswith('Heading'):
|
|
|
|
|
- question = paragraph.text
|
|
|
|
|
- answer = doc.paragraphs[index + 1].text
|
|
|
|
|
- save_image(question, answer, folder_path)
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-def save_image(question, answer, folder_path):
|
|
|
|
|
- image_name = f"{question.replace(' ', '-')}.png"
|
|
|
|
|
- image_path = os.path.join(folder_path, image_name)
|
|
|
|
|
- print(f"Saving image {image_name}...")
|
|
|
|
|
- image = ImageGrab.grab(question)
|
|
|
|
|
- image.save(image_path)
|
|
|
|
|
-
|
|
|
|
|
-if __name__ == "__main__":
|
|
|
|
|
- word_file = "test.docx"
|
|
|
|
|
- folder_path = "images"
|
|
|
|
|
-
|
|
|
|
|
- doc = Document(word_file)
|
|
|
|
|
- save_images(doc, folder_path)
|
|
|