Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7129e69
ENH: Enhance XMP metadata handling with creation and setter methods
Arya-A-Nair Jul 30, 2025
cfef29e
Merge branch 'main' into feature/xmp-create-method
Arya-A-Nair Jul 31, 2025
d410bee
Fix XMP implementation: Add missing List import and setter methods
Arya-A-Nair Jul 31, 2025
1e862d8
Add comprehensive test coverage for XMP implementation
Arya-A-Nair Jul 31, 2025
1abdf04
Add XmpInformation.create() method with Pythonic properties
Arya-A-Nair Jul 31, 2025
fc0386d
Add tests for XMP error handling and attribute removal
Arya-A-Nair Jul 31, 2025
ec70685
Merge branch 'main' into feature/xmp-create-method
Arya-A-Nair Aug 1, 2025
574b45b
Merge branch 'main' into feature/xmp-create-method
Arya-A-Nair Aug 4, 2025
2247b45
Merge branch 'main' into feature/xmp-create-method
Arya-A-Nair Aug 10, 2025
43e65ca
ENH: move minimal xmp template to constant
Arya-A-Nair Aug 13, 2025
8dec225
Merge branch 'main' into feature/xmp-create-method
Arya-A-Nair Aug 13, 2025
4c0d6b7
REF: Update XmpInformation class to use property-based access for met…
Arya-A-Nair Aug 13, 2025
452994d
REF: Refactor XmpInformation class to replace getter functions with d…
Arya-A-Nair Aug 13, 2025
663bb8c
ENH: Introduce XmpDocumentError for improved error handling in XMP pr…
Arya-A-Nair Aug 13, 2025
d96cb7d
REF: Rename _get_bag_values to _getter_bag for improved clarity in Xm…
Arya-A-Nair Aug 13, 2025
73d3e00
REF: Consolidate namespace prefix mapping in XmpInformation class for…
Arya-A-Nair Aug 13, 2025
f1ac2da
REF: Rename test_xmp_information_create to test_xmp_information__crea…
Arya-A-Nair Aug 13, 2025
8ced8b9
REF: Introduce _clear_cache_entry method in XmpInformation class to s…
Arya-A-Nair Aug 13, 2025
878d673
REF: Update _update_stream method in XmpInformation class to comply w…
Arya-A-Nair Aug 13, 2025
38e1604
ENH: Add methods to XmpInformation class for incrementally updating X…
Arya-A-Nair Aug 13, 2025
4c2a365
ENH: Add unit tests for additive helpers in XmpInformation class to v…
Arya-A-Nair Aug 13, 2025
c115ee0
REF: Rename constants in xmp.py for consistency and clarity, updating…
Arya-A-Nair Aug 15, 2025
99878dc
Merge branch 'main' into feature/xmp-create-method
Arya-A-Nair Aug 15, 2025
3755449
REF: Remove additive helper methods from XmpInformation class and upd…
Arya-A-Nair Aug 15, 2025
9a13b65
Merge branch 'feature/xmp-create-method' of github.com:Arya-A-Nair/py…
Arya-A-Nair Aug 15, 2025
8cabff0
Merge branch 'main' into feature/xmp-create-method
Arya-A-Nair Aug 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions docs/user/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,113 @@ if meta:
print(meta.xmp_create_date)
```

## Creating XMP metadata

You can create XMP metadata easily using the `XmpInformation.create()` method:

```python
from pypdf import PdfWriter
from pypdf.xmp import XmpInformation

# Create a new XMP metadata object
xmp = XmpInformation.create()

# Set metadata fields
xmp.set_dc_title({"x-default": "My Document Title"})
xmp.set_dc_creator(["Author One", "Author Two"])
xmp.set_dc_description({"x-default": "Document description"})
xmp.set_dc_subject(["keyword1", "keyword2", "keyword3"])
xmp.set_pdf_producer("pypdf")

# Create a writer and add the metadata
writer = PdfWriter()
writer.add_blank_page(612, 792) # Add a page
writer.xmp_metadata = xmp
writer.write("output.pdf")
```

## Setting XMP metadata fields

The `XmpInformation` class provides setter methods for all supported metadata fields:

### Dublin Core fields

```python
from datetime import datetime
from pypdf.xmp import XmpInformation

xmp = XmpInformation.create()

# Single value fields
xmp.set_dc_coverage("Global coverage")
xmp.set_dc_format("application/pdf")
xmp.set_dc_identifier("unique-id-123")
xmp.set_dc_source("Original Source")

# Array fields (bags - unordered)
xmp.set_dc_contributor(["Contributor One", "Contributor Two"])
xmp.set_dc_language(["en", "fr", "de"])
xmp.set_dc_publisher(["Publisher One"])
xmp.set_dc_relation(["Related Doc 1", "Related Doc 2"])
xmp.set_dc_subject(["keyword1", "keyword2"])
xmp.set_dc_type(["Document", "Text"])

# Sequence fields (ordered arrays)
xmp.set_dc_creator(["Primary Author", "Secondary Author"])
xmp.set_dc_date([datetime.now()])

# Language alternative fields
xmp.set_dc_title({"x-default": "Title", "en": "English Title", "fr": "Titre français"})
xmp.set_dc_description({"x-default": "Description", "en": "English Description"})
xmp.set_dc_rights({"x-default": "All rights reserved"})
```

### XMP fields

```python
from datetime import datetime

# Date fields accept both datetime objects and strings
xmp.set_xmp_create_date(datetime.now())
xmp.set_xmp_modify_date("2023-12-25T10:30:45Z")
xmp.set_xmp_metadata_date(datetime.now())

# Text field
xmp.set_xmp_creator_tool("pypdf")
```

### PDF fields

```python
xmp.set_pdf_keywords("keyword1, keyword2, keyword3")
xmp.set_pdf_pdfversion("1.4")
xmp.set_pdf_producer("pypdf")
```

### XMP Media Management fields

```python
xmp.set_xmpmm_document_id("uuid:12345678-1234-1234-1234-123456789abc")
xmp.set_xmpmm_instance_id("uuid:87654321-4321-4321-4321-cba987654321")
```

### PDF/A fields

```python
xmp.set_pdfaid_part("1")
xmp.set_pdfaid_conformance("B")
```

### Clearing metadata fields

You can clear any field by passing `None`:

```python
xmp.set_dc_title(None)
xmp.set_dc_creator(None)
xmp.set_pdf_producer(None)
```

## Modifying XMP metadata

Modifying XMP metadata is a bit more complicated.
Expand Down
Loading
Loading