With the help of Change metadata of pdf file with pypdf2 I worte the code below to add new metadata to a pdf-document, which runs perfectly. Nevertheless I cannot view the new Metadata when opening the details of my document. How can I view the new meta data in the details?
Note: I need to add the metadata "comments", which is readable for Elasticsearch
from PyPDF2 import PdfFileReader, PdfFileWriter
def editMeta(file, text):
fin = open(file, 'rb')
reader = PdfFileReader(fin)
writer = PdfFileWriter()
writer.appendPagesFromReader(reader)
metadata = reader.getDocumentInfo()
writer.addMetadata(metadata)
writer.addMetadata({
'/comments': text
})
fout = open(file, 'ab')
writer.write(fout)
fin.close()
fout.close()
if __name__ == "__main__":
file = 'Test_Angebot.pdf'
editMeta(file, '#cool')
read the metadata via python:
def get_info(file):
with open(file, 'rb') as f:
pdf = PdfFileReader(f)
info = pdf.getDocumentInfo()
print(info)