Skip to content

fix(pptx): extract the picture of a picture-filled shape - #4989

Merged
PeterStaar-IBM merged 4 commits into
docling-project:mainfrom
sarankumar1325:fix/pptx-picture-fill-shape
Oct 26, 2026
Merged

PeterStaar-IBM merged 4 commits into
docling-project:mainfrom
sarankumar1325:fix/pptx-picture-fill-shape

Conversation

@sarankumar1325

Copy link
Copy Markdown
Contributor

A shape filled with a picture (Format Shape > Fill > Picture or texture fill) is a p:sp with an a:blipFill in its p:spPr. python-pptx reads it as an Autoshape, not a Picture, so handle_shape_content only took the text path. A picture-filled shape with no text was skipped silently, and its image was lost.

This change adds _picture_fill_rid(), which returns the r:embed id of a shape's p:spPr/a:blipFill/a:blip. When a Shape has one, _handle_pictures reads the image from the related image part (shape.part.related_part(rid).image) and adds a PictureItem with the shape's provenance, the same way it does for a p:pic, including the existing malformed-image and metafile handling. Any text in the shape is still added after the picture. Fills that only link an external image (r:link) are left out because there are no bytes in the package. p:pic shapes, groups and placeholders are unchanged.

Issue resolved by this Pull Request:
Resolves #4988

Checklist:

  • Documentation has been updated, if necessary. (docstring of _picture_fill_rid)
  • Examples have been added, if necessary. (n/a)
  • Tests have been added, if necessary.

Review evidence:

  • Before: the reproducer from the issue (a rectangle filled with a PNG) converts to a document with 0 pictures, holding only the empty slide group.
  • After: 1 PictureItem (image/png, the original 64x32 size, page 1 provenance with the shape's bbox).
  • New tests in tests/test_backend_pptx.py:
    • test_pptx_picture_filled_shape_is_extracted: the issue's case.
    • test_pptx_picture_filled_shape_keeps_its_text: the picture and the shape's text are both kept.
    • test_pptx_linked_picture_fill_is_ignored: a linked fill adds no picture and the text is kept.
    • The first two fail on main and pass with the change. The third passes on both and guards the linked case.
  • uv run pytest tests/test_backend_pptx*.py: 82 passed. None of the PPTX files in tests/data has a picture-filled p:sp, so no reference data changed.
  • ruff format --check and ruff check are clean. ty check docling/backend/mspowerpoint_backend.py reports the same 7 diagnostics as on main, all on unchanged lines.
  • I did not run the full test suite, only the PPTX backend tests.

This fix was prepared with AI assistance; I reviewed the change and ran the checks above.

A shape filled with a picture (p:sp with a:blipFill in p:spPr) is read by
python-pptx as an Autoshape, so only its text was handled and the image
was dropped. Extract the embedded fill image as a picture item, like a
p:pic, and keep the shape's text as well. Linked fills are left out.

Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @sarankumar1325, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working pptx issue related to pptx backend labels Oct 23, 2026
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit f39e2af089. The analysis read the diff only. It did not run code from this pull request.

This pull request extracts embedded images from PowerPoint shapes that have a picture fill.

CI safety: no concern found. A maintainer must still approve CI.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): no blocker found

This review covers the full diff at 02ea328f73. It read the code and did not run it.

The changes correctly extract embedded picture fills from PowerPoint autoshapes while preserving associated shape text and ignoring external links. I checked relationship resolution via shape.part.related_part, exception handling for malformed fills, provenance generation, and test coverage across embedded and linked fills.

A maintainer makes the merge decision. This review never approves the pull request.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Oct 23, 2026
@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

tests/test_backend_pptx.py went over the 1500-line limit of the max-lines
hook. Also cover a fill whose relationship is missing.

Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) labels Oct 23, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): no blocker found

This review covers the changes since 02ea328f73 at 00ef272e72. It read the code and did not run it.

The incremental change moves the picture-fill tests into tests/test_backend_pptx_picture_fill.py and adds a test case for missing relationship targets. I checked relationship handling, warning assertions, and shape text extraction across the test cases.

A maintainer makes the merge decision. This review never approves the pull request.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Oct 23, 2026
Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) labels Oct 23, 2026

@uommou uommou left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up so quickly! I opened #4988, so I checked the change against the case in the issue.

What I ran on 41a2daff:

  • pytest tests/test_backend_pptx.py tests/test_backend_pptx_*.py: 86 passed.
  • The new test file against the base mspowerpoint_backend.py (5de229e5): 6 of 7 fail, so the tests catch the original defect. test_pptx_linked_picture_fill_is_ignored passes on the base too, as expected.
  • The reproducer from the issue: base gives 0 pictures; head gives 1 PictureItem before the shape's TextItem, with bbox (914400, 914400, 2743200, 1828800), which matches the shape.

Not run: make check (CI lint-and-type passes on this head).

I left one small suggestion inline.

Comment thread docling/backend/mspowerpoint_backend.py Outdated
Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) labels Oct 24, 2026
@sarankumar1325

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Good call on linked-only fills. I've added a UserWarning when a picture fill has no embedded image, plus tests for it, in the latest commit.

@PeterStaar-IBM PeterStaar-IBM left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@PeterStaar-IBM
PeterStaar-IBM merged commit 4ad544a into docling-project:main Oct 26, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working pptx issue related to pptx backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PPTX: a shape filled with a picture (a:blipFill) is dropped instead of extracted as a picture

3 participants