Skip to content

Commit

Permalink
Add option to output only annotated pages
Browse files Browse the repository at this point in the history
Closes #3.
  • Loading branch information
rschroll committed Feb 28, 2021
1 parent 7318765 commit 5baa9e7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions rmrl/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
def render(source, *,
progress_cb=lambda x: None,
expand_pages=True,
template_alpha=0.3):
template_alpha=0.3,
only_annotated=False):
# Exports the self as a PDF document to disk

# progress_cb will be called with a progress percentage between 0 and
Expand Down Expand Up @@ -149,9 +150,16 @@ def render(source, *,
else:
basepdfr.Root.OCProperties = ocgprop

pdfw = PdfWriter()
stream = tempfile.SpooledTemporaryFile(SPOOL_MAX)
pdfw.write(stream, basepdfr)
pdfw = PdfWriter(stream)
if not only_annotated:
# We are writing out everything, so we can take this shortcut:
pdfw.write(trailer=basepdfr)
else:
for i, page in enumerate(basepdfr.pages):
if i in changed_pages:
pdfw.addpage(page)
pdfw.write()
stream.seek(0)

log.info('exported pdf')
Expand Down

0 comments on commit 5baa9e7

Please sign in to comment.