Skip to content

Commit

Permalink
tocprinter: avoid some variable assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 committed Sep 22, 2022
1 parent ff52551 commit 1b8d7f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ Here are some examples of using the support model API.
* Read the table of contents
```python
for item in pdf.get_toc():
for item in toc:
if item.n_kids == 0:
state = "*"
elif item.is_closed:
Expand All @@ -127,12 +127,13 @@ Here are some examples of using the support model API.
else:
target = item.page_index + 1
view_mode = pdfium.ViewmodeToStr[item.view_mode]
view_pos = [round(c, n_digits) for c in item.view_pos]
print(
" " * item.level +
"[%s] %s -> %s # %s %s" % (state, item.title, target, view_mode, view_pos)
"[%s] %s -> %s # %s %s" % (
state, item.title, target,
pdfium.ViewmodeToStr[item.view_mode],
[round(c, n_digits) for c in item.view_pos],
)
)
```
Expand Down Expand Up @@ -160,7 +161,6 @@ Here are some examples of using the support model API.
greyscale = False, # coloured output
fill_colour = (255, 255, 255, 255), # fill bitmap with white background before rendering (form: RGBA)
colour_scheme = None, # no custom colour scheme
fill_to_stroke = False, # don't stroke fill paths (relevant for custom colour scheme only)
optimise_mode = OptimiseMode.NONE, # no optimisations (e. g. subpixel rendering)
draw_annots = True, # show annotations
draw_forms = True, # show forms
Expand Down
9 changes: 5 additions & 4 deletions src/pypdfium2/_helpers/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,13 @@ def print_toc(toc, n_digits=2):
else:
target = item.page_index + 1

view_mode = ViewmodeToStr[item.view_mode]
view_pos = [round(c, n_digits) for c in item.view_pos]

print(
" " * item.level +
"[%s] %s -> %s # %s %s" % (state, item.title, target, view_mode, view_pos)
"[%s] %s -> %s # %s %s" % (
state, item.title, target,
ViewmodeToStr[item.view_mode],
[round(c, n_digits) for c in item.view_pos],
)
)


Expand Down

0 comments on commit 1b8d7f1

Please sign in to comment.