Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Extracting picture data for raster images found in PPTX #349

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion docling/backend/mspowerpoint_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
DoclingDocument,
DocumentOrigin,
GroupLabel,
ImageRef,
ProvenanceItem,
Size,
TableCell,
TableData,
)
from PIL import Image
from pptx import Presentation
from pptx.enum.shapes import MSO_SHAPE_TYPE, PP_PLACEHOLDER

Expand Down Expand Up @@ -268,9 +270,20 @@ def handle_title(self, shape, parent_slide, slide_ind, doc):
return

def handle_pictures(self, shape, parent_slide, slide_ind, doc):
# Get the image bytes
image = shape.image
image_bytes = image.blob
# Open it with PIL
pil_image = Image.open(BytesIO(image_bytes))

# shape has picture
prov = self.generate_prov(shape, slide_ind, "")
doc.add_picture(parent=parent_slide, caption=None, prov=prov)
doc.add_picture(
parent=parent_slide,
image=ImageRef.from_pil(image=pil_image, dpi=72),
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to hard-code 72 DPI here? I guess we have no better information about the actual DPI?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added another commit, now extracting image DPI from the input file

caption=None,
prov=prov,
)
return

def handle_tables(self, shape, parent_slide, slide_ind, doc):
Expand Down
35 changes: 35 additions & 0 deletions tests/data/groundtruth/docling_v2/powerpoint_sample.pptx.itxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
item-0 at level 0: unspecified: group _root_
item-1 at level 1: chapter: group slide-0
item-2 at level 2: title: Test Table Slide
item-3 at level 2: paragraph: With footnote
item-4 at level 2: table with [9x7]
item-5 at level 1: chapter: group slide-1
item-6 at level 2: title: Second slide title
item-7 at level 2: paragraph: Let’s introduce a list
item-8 at level 2: paragraph: With foo
item-9 at level 2: paragraph: Bar
item-10 at level 2: paragraph: And baz things
item-11 at level 2: paragraph: A rectangle shape with this text inside.
item-12 at level 1: chapter: group slide-2
item-13 at level 2: ordered_list: group list
item-14 at level 3: list_item: List item4
item-15 at level 3: list_item: List item5
item-16 at level 3: list_item: List item6
item-17 at level 2: list: group list
item-18 at level 3: list_item: I1
item-19 at level 3: list_item: I2
item-20 at level 3: list_item: I3
item-21 at level 3: list_item: I4
item-22 at level 2: paragraph: Some info:
item-23 at level 2: list: group list
item-24 at level 3: list_item: Item A
item-25 at level 3: list_item: Item B
item-26 at level 2: paragraph: Maybe a list?
item-27 at level 2: ordered_list: group list
item-28 at level 3: list_item: List1
item-29 at level 3: list_item: List2
item-30 at level 3: list_item: List3
item-31 at level 2: list: group list
item-32 at level 3: list_item: l1
item-33 at level 3: list_item: l2
item-34 at level 3: list_item: l3
Loading
Loading