Skip to content

Commit af6aabf

Browse files
author
ashariyar
committed
Handle AttributeError in FontInfo extraction
1 parent 967aa82 commit af6aabf

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# NEXT RELEASE
2+
* Handle `AttributeError` in `FontInfo` extraction
23

34
### 1.17.7
45
* Bump `pypdf` to 6.1.3 (fixes [#31](https://github.com/michelcrypt4d4mus/pdfalyzer/issues/31)), `PyMuPDF` to 1.26.5

pdfalyzer/pdfalyzer.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,20 @@ def _resolve_indeterminate_nodes(self) -> None:
220220
def _extract_font_infos(self) -> None:
221221
"""Extract information about fonts in the tree and place it in `self.font_infos`."""
222222
for node in self.node_iterator():
223-
if isinstance(node.obj, dict) and RESOURCES in node.obj:
224-
log.debug(f"Extracting fonts from node with '{RESOURCES}' key: {node}...")
225-
known_font_ids = [fi.idnum for fi in self.font_infos]
223+
if not (isinstance(node.obj, dict) and RESOURCES in node.obj):
224+
continue
225+
226+
log.debug(f"Extracting fonts from node with '{RESOURCES}' key: {node}...")
227+
known_font_ids = [fi.idnum for fi in self.font_infos]
226228

229+
try:
227230
self.font_infos += [
228231
fi for fi in FontInfo.extract_font_infos(node.obj)
229232
if fi.idnum not in known_font_ids
230233
]
234+
except AttributeError as e:
235+
console.print_exception()
236+
log.error(f"Failed to extract font information from node: {node}")
231237

232238
def _build_or_find_node(self, relationship: IndirectObject, relationship_key: str) -> PdfTreeNode:
233239
"""If node in self.nodes_encountered already then return it, otherwise build a node and store it."""

0 commit comments

Comments
 (0)