Skip to content

Commit cc114d7

Browse files
committed
Address #4404
The example PDF's "/Dests" dictionary has multiple destinations per destination name - which is against the specifications. This fix makes sure to only accept the first "/XYZ" destination.
1 parent b1ecfe6 commit cc114d7

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/__init__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5425,26 +5425,28 @@ def get_array(val):
54255425
templ_dict["dest"] = array # return the orig. string
54265426
return templ_dict
54275427

5428-
subval = array[:idx] # stuff before "/"
5428+
subval = array[:idx].strip() # stuff before "/"
54295429
array = array[idx:] # stuff from "/" onwards
54305430
templ_dict["dest"] = array
5431-
54325431
# if we start with /XYZ: extract x, y, zoom
54335432
# 1, 2 or 3 of these values may actually be supplied
54345433
if array.startswith("/XYZ"):
54355434
del templ_dict["dest"] # don't return orig string in this case
54365435

5437-
t = [0, 0, 0] # the resulting x, y, z values
5436+
# make a list of the 3 tokens following "/XYZ"
5437+
array_list = array.split()[1:4] # omit "/XYZ"
5438+
5439+
# fill up missing tokens with "0" strings
5440+
while len(array_list) < 3: # fill up if too short
5441+
array_list.append("0") # add missing values
54385442

5439-
# need to replace any "null" item by "0", then split at
5440-
# white spaces, omitting "/XYZ" from the result
5441-
for i, v in enumerate(array.replace("null", "0").split()[1:]):
5442-
t[i] = float(v)
5443+
# make list of 3 floats: x, y and zoom
5444+
t = list(map(float, array_list)) # the resulting x, y, z values
54435445
templ_dict["to"] = (t[0], t[1])
54445446
templ_dict["zoom"] = t[2]
54455447

54465448
# extract page number
5447-
if "0 R" in subval: # page xref given?
5449+
if subval.endswith("0 R"): # page xref given?
54485450
templ_dict["page"] = page_xrefs.get(int(subval.split()[0]),-1)
54495451
else: # naked page number given
54505452
templ_dict["page"] = int(subval)

0 commit comments

Comments
 (0)