diff --git a/src/cpr_data_access/parser_models.py b/src/cpr_data_access/parser_models.py index 2998394..22c4607 100644 --- a/src/cpr_data_access/parser_models.py +++ b/src/cpr_data_access/parser_models.py @@ -328,21 +328,27 @@ def vertically_flip_text_block_coords(self: _PO) -> _PO: page.page_number: page.dimensions[1] for page in self.pdf_data.page_metadata } - for text_block in self.pdf_data.text_blocks: - if text_block.coords is not None and text_block.page_number is not None: - text_block.coords = [ - (x, page_height_map[text_block.page_number] - y) - for x, y in text_block.coords - ] - - # flip top and bottom so y values are still increasing as you go - # through the coordinates list - text_block.coords = [ - text_block.coords[3], - text_block.coords[2], - text_block.coords[1], - text_block.coords[0], - ] + try: + for text_block in self.pdf_data.text_blocks: + if text_block.coords is not None and text_block.page_number is not None: + text_block.coords = [ + (x, page_height_map[text_block.page_number] - y) + for x, y in text_block.coords + ] + + # flip top and bottom so y values are still increasing as you go + # through the coordinates list + text_block.coords = [ + text_block.coords[3], + text_block.coords[2], + text_block.coords[1], + text_block.coords[0], + ] + except Exception: + logger.exception( + "Error flipping text block coordinates.", + extra={"props": {"document_id": self.document_id}}, + ) return self