From 4f39d0364d4a5ec515d34dfcad4ee53d142d149b Mon Sep 17 00:00:00 2001 From: Jeremy Singer-Vine Date: Sat, 10 Feb 2024 18:31:17 -0500 Subject: [PATCH] Check self.cur_item._objs length before [-1] In theory shouldn't happen, but came across a malformed PDF that threw an error here; simple enough check that seemed worth adding. --- pdfplumber/page.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pdfplumber/page.py b/pdfplumber/page.py index c458ab9..8500a6a 100644 --- a/pdfplumber/page.py +++ b/pdfplumber/page.py @@ -147,9 +147,10 @@ class PDFPageAggregatorWithMarkedContent(PDFPageAggregator): # create one object, but that is far from being guaranteed. # Even if pdfminer.six's API would just return the objects it # creates, we wouldn't have to do this. - cur_obj = self.cur_item._objs[-1] - cur_obj.mcid = self.cur_mcid # type: ignore - cur_obj.tag = self.cur_tag # type: ignore + if self.cur_item._objs: + cur_obj = self.cur_item._objs[-1] + cur_obj.mcid = self.cur_mcid # type: ignore + cur_obj.tag = self.cur_tag # type: ignore def render_char(self, *args, **kwargs) -> float: # type: ignore """Hook for rendering characters, adding the `mcid` attribute."""