Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

Fix: the pict type picture was not processed in the docx (#19305)

helojoe7d80bf7bfa8
diff --git a/api/core/rag/extractor/word_extractor.py b/api/core/rag/extractor/word_extractor.py
index bff0acc48f7..14363de7d4c 100644
--- a/api/core/rag/extractor/word_extractor.py
+++ b/api/core/rag/extractor/word_extractor.py
@@ -238,9 +238,11 @@ class WordExtractor(BaseExtractor):
paragraph_content = []
for run in paragraph.runs:
if hasattr(run.element, "tag") and isinstance(run.element.tag, str) and run.element.tag.endswith("r"):
+ # Process drawing type images
drawing_elements = run.element.findall(
".//{http://schemas.openxmlformats.org/wordprocessingml/2006/main}drawing"
)
+ has_drawing = False
for drawing in drawing_elements:
blip_elements = drawing.findall(
".//{http://schemas.openxmlformats.org/drawingml/2006/main}blip"
@@ -252,6 +254,34 @@ class WordExtractor(BaseExtractor):
if embed_id:
image_part = doc.part.related_parts.get(embed_id)
if image_part in image_map:
+ has_drawing = True
+ paragraph_content.append(image_map[image_part])
+ # Process pict type images
+ shape_elements = run.element.findall(
+ ".//{http://schemas.openxmlformats.org/wordprocessingml/2006/main}pict"
+ )
+ for shape in shape_elements:
+ # Find image data in VML
+ shape_image = shape.find(
+ ".//{http://schemas.openxmlformats.org/wordprocessingml/2006/main}binData"
+ )
+ if shape_image is not None and shape_image.text:
+ image_id = shape_image.get(
+ "{http://schemas.openxmlformats.org/officeDocument/2006/relationships}id"
+ )
+ if image_id and image_id in doc.part.rels:
+ image_part = doc.part.rels[image_id].target_part
+ if image_part in image_map and not has_drawing:
+ paragraph_content.append(image_map[image_part])
+ # Find imagedata element in VML
+ image_data = shape.find(".//{urn:schemas-microsoft-com:vml}imagedata")
+ if image_data is not None:
+ image_id = image_data.get("id") or image_data.get(
+ "{http://schemas.openxmlformats.org/officeDocument/2006/relationships}id"
+ )
+ if image_id and image_id in doc.part.rels:
+ image_part = doc.part.rels[image_id].target_part
+ if image_part in image_map and not has_drawing:
paragraph_content.append(image_map[image_part])
if run.text.strip():
paragraph_content.append(run.text.strip())