From 8cacb0fc8fee9920b0515d1289e6ee8191eb3f21 Mon Sep 17 00:00:00 2001 From: Stefan <96178532+stefan6419846@users.noreply.github.com> Date: Tue, 13 Feb 2024 22:33:37 +0100 Subject: [PATCH] DOC: Document easier way to update metadata (#2454) --- docs/user/metadata.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/user/metadata.md b/docs/user/metadata.md index b71cc778e..7f7ceda00 100644 --- a/docs/user/metadata.md +++ b/docs/user/metadata.md @@ -59,3 +59,24 @@ writer.add_metadata( with open("meta-pdf.pdf", "wb") as f: writer.write(f) ``` + +## Updating metadata + +```python +from pypdf import PdfReader, PdfWriter + +writer = PdfWriter(clone_from="example.pdf") + +# Change some values. +writer.add_metadata( + { + "/Author": "Martin", + "/Producer": "Libre Writer", + "/Title": "Title", + } +) + +# Save the new PDF to a file +with open("meta-pdf.pdf", "wb") as f: + writer.write(f) +```