Skip to content

Commit

Permalink
DOC: Make code example more robust (#2609)
Browse files Browse the repository at this point in the history
The example failed when a PDF file did not contain any metadata.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Apr 30, 2024
1 parent 6d9a7ec commit 40dc70c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/user/file-size.md
Expand Up @@ -20,7 +20,8 @@ writer = PdfWriter()
for page in reader.pages:
writer.add_page(page)

writer.add_metadata(reader.metadata)
if reader.metadata is not None:
writer.add_metadata(reader.metadata)

with open("smaller-new-file.pdf", "wb") as fp:
writer.write(fp)
Expand Down

0 comments on commit 40dc70c

Please sign in to comment.