PyMuPDF icon indicating copy to clipboard operation
PyMuPDF copied to clipboard

Set_metadata() does not work

Open JorjMcKie opened this issue 1 year ago • 1 comments

Discussed in https://github.com/pymupdf/PyMuPDF/discussions/3236

Originally posted by rockerjunge March 7, 2024

Description of the bug

I'm new to programming and still finding my way around, but I've encountered an issue with the set_metadata() function. Unfortunately, I can't seem to get it to work correctly. Below is my code where I've implemented this method. Despite my efforts, both print statements yield identical results, with the metadata still present.

How to reproduce the bug

import os
import fitz
def test_method(input_dir, output_dir):
    for filename in os.listdir(input_dir):
        if filename.endswith(".pdf"):
            pdf_path = os.path.join(input_dir, filename)
            output_path = os.path.join(output_dir, filename.replace(".pdf", "_test.pdf"))

            doc = fitz.open(pdf_path)
           
            print(doc.metadata)
            doc.set_metadata({})
            print(doc.metadata)

            doc.save(output_path, garbage=4)
            doc.close()

input_dir = "H:\\Schwärzer Test"
output_dir = "H:\\Schwärzer Test\\Geschwaerzt"

if not os.path.exists(output_dir):
    os.makedirs(output_dir)

test_method(input_dir, output_dir)

PyMuPDF version

1.23.26

Operating system

Windows

Python version

3.11

JorjMcKie avatar Mar 07 '24 17:03 JorjMcKie

This only pertains to missing updating the dictionary afterwards. The document is being changed and can be save as expected.

JorjMcKie avatar Mar 07 '24 18:03 JorjMcKie

Addressed in #3555.

Fixed in 1.24.6.