|
16 | 16 | TableCell,
|
17 | 17 | TableData,
|
18 | 18 | )
|
19 |
| -from PIL import Image |
| 19 | +from PIL import Image, UnidentifiedImageError |
20 | 20 | from pptx import Presentation
|
21 | 21 | from pptx.enum.shapes import MSO_SHAPE_TYPE, PP_PLACEHOLDER
|
22 | 22 |
|
@@ -120,6 +120,7 @@ def handle_text_elements(self, shape, parent_slide, slide_ind, doc):
|
120 | 120 | bullet_type = "None"
|
121 | 121 | list_text = ""
|
122 | 122 | list_label = GroupLabel.LIST
|
| 123 | + doc_label = DocItemLabel.LIST_ITEM |
123 | 124 | prov = self.generate_prov(shape, slide_ind, shape.text.strip())
|
124 | 125 |
|
125 | 126 | # Identify if shape contains lists
|
@@ -276,16 +277,19 @@ def handle_pictures(self, shape, parent_slide, slide_ind, doc):
|
276 | 277 | im_dpi, _ = image.dpi
|
277 | 278 |
|
278 | 279 | # Open it with PIL
|
279 |
| - pil_image = Image.open(BytesIO(image_bytes)) |
280 |
| - |
281 |
| - # shape has picture |
282 |
| - prov = self.generate_prov(shape, slide_ind, "") |
283 |
| - doc.add_picture( |
284 |
| - parent=parent_slide, |
285 |
| - image=ImageRef.from_pil(image=pil_image, dpi=im_dpi), |
286 |
| - caption=None, |
287 |
| - prov=prov, |
288 |
| - ) |
| 280 | + try: |
| 281 | + pil_image = Image.open(BytesIO(image_bytes)) |
| 282 | + |
| 283 | + # shape has picture |
| 284 | + prov = self.generate_prov(shape, slide_ind, "") |
| 285 | + doc.add_picture( |
| 286 | + parent=parent_slide, |
| 287 | + image=ImageRef.from_pil(image=pil_image, dpi=im_dpi), |
| 288 | + caption=None, |
| 289 | + prov=prov, |
| 290 | + ) |
| 291 | + except (UnidentifiedImageError, OSError) as e: |
| 292 | + _log.warning(f"Warning: image cannot be loaded by Pillow: {e}") |
289 | 293 | return
|
290 | 294 |
|
291 | 295 | def handle_tables(self, shape, parent_slide, slide_ind, doc):
|
|
0 commit comments