docling-project / docling-project/docling

Markdown conversion from pptx files with figures has multiple issues depending on the method used

Open
#454 2 comments 2 reactions 1 assignee Claimed by @maxmnemonic View on GitHub
bug pptx
Dominant language
Python
Stars
66.4k
Forks
4.8k
Avg merge
2d 21h
Merged PRs (30d)
84

Description

### Preface
Issue https://github.com/DS4SD/docling/issues/211 was closed by https://github.com/DS4SD/docling-core/pull/69. I wasn't sure if my suggestion https://github.com/DS4SD/docling/issues/211#issuecomment-2467621421 to allow exporting images when converting from pptx was implemented or not - so I gave it a try.

### Test file
- This is my pptx for testing: [test.pptx](https://github.com/user-attachments/files/17935068/test.pptx)
- There are two images in the pptx-content directory `/ppt/media`:
- `image1.png`: Was inserted by copy pasting a screenshot
- `image2.png`: Was inserted by embedding an image from the filesystem
- This is how it looks:
![image](https://github.com/user-attachments/assets/9b3fe4e7-a0e3-438c-bc49-9982131564f9)

### Environment
```
OS: Windows 11 Enterprise 24H2
Python 3.12.7
```

### Docling version
```
Docling version: 2.7.1
Docling Core version: 2.5.0
Docling IBM Models version: 2.0.6
Docling Parse version: 2.1.2
```

### Code for reproduction
I have added comments with the observations for each method. As there seem to be multiple issues and I wasn't sure if some of them are already known, I included all of them in the description.
```python
from docling_core.types.doc import ImageRefMode
from docling.document_converter import DocumentConverter

source = "test.pptx"
converter = DocumentConverter()
result = converter.convert(source)

# TEST_1: Try save_as_markdown
# File "docling_core\types\doc\document.py", line 2039, in _get_output_paths
# AttributeError: 'str' object has no attribute 'with_suffix' ❌
result.document.save_as_markdown("test.md", image_mode=ImageRefMode.REFERENCED)

# TEST_2: Try export_to_markdown with (implicit) ImageRefMode.PLACEHOLDER
# image1: Not recognized ❌
# image2: Placeholder ✅
# Also the recognized text has lost some whitespace and the bullet points formatting❓
markdown_placeholder = result.document.export_to_markdown()
with open("test_placeholder.md", "w", encoding="utf-8") as markdown_file:
markdown_file.write(markdown_placeholder)

# TEST_3: Try export_to_markdown with ImageRefMode.REFERENCED
# image1: Not recognized ❌
# image2: Embedded instead of referenced ❓
# Base64 encoded image2 is not working in VSCode Markdown Preview, html-export and other base64-to-image-converters
# Maybe because of base64 errors
# • Invalid string \r
# • Invalid string \n
# • Invalid character \
markdown_referenced = result.document.export_to_markdown(image_mode=ImageRefMode.REFERENCED)
with open("test_referenced.md", "w", encoding="utf-8") as markdown_file:
markdown_file.write(markdown_referenced)

# TEST_4: Try export_to_markdown with ImageRefMode.EMBEDDED
# Text ist printed to console ❓
# Code does not reach saving the file! Was there an error catched and not reported ❓
markdown_embedded = result.document.export_to_markdown(image_mode=ImageRefMode.EMBEDDED)
with open("test_embedded.md", "w", encoding="utf-8") as markdown_file:
markdown_file.write(markdown_embedded)
```

### Markdown only result
```markdown
# This istheheading

This is a text.

This is a bulletpoint

This isanotherbulletpoint
```

### Further notes
- My code could be totally wrong. I tried to keep it simple but maybe I missed some important steps. My only references were
- https://github.com/DS4SD/docling?tab=readme-ov-file#getting-started
- https://ds4sd.github.io/docling/examples/export_figures/
- https://github.com/DS4SD/docling-core/blob/main/docling_core/types/doc/document.py.
- The description of https://github.com/DS4SD/docling-core/pull/69 talks about `save_images_to_disk` but I was not able to find that function in the whole codebase of docling or docling_core.
- I'm not sure why there is a difference in recognizing images depending on the method used to embed them into the pptx. I would like to understand how pptx conversion is implemented but haven't found the important parts in the codebase.
- Maybe there is a need for another example ins the docs after https://github.com/DS4SD/docling-core/pull/69 was merged

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.