Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep original metadata #57

Closed
City-busz opened this issue Mar 11, 2019 · 1 comment
Closed

Keep original metadata #57

City-busz opened this issue Mar 11, 2019 · 1 comment
Labels
feature Request for a new feature
Milestone

Comments

@City-busz
Copy link

When I save edited PDF documents, the original metadata is lost. There is no way to keep the original title, author, keywords, creation date etc. It would be a nice feature to keep these metadata on save/export, or even allow to edit these fields.

@jeromerobert
Copy link
Member

From https://stackoverflow.com/questions/46849733/change-metadata-of-pdf-file-with-pypdf2 this should be easy to implement:

from PyPDF2 import PdfFileReader, PdfFileWriter

fin = open('source.pdf', 'rb')
reader = PdfFileReader(fin)

writer.appendPagesFromReader(reader)
metadata = reader.getDocumentInfo()
writer.addMetadata(metadata)

# Write your custom metadata here:
writer.addMetadata({
    '/Some': 'Example'
})

fout = open('result.pdf', 'wb')
writer.write(fout)

fin.close()
fout.close()

@dreua dreua added this to the 1.2 milestone Mar 14, 2022
@dreua dreua added the feature Request for a new feature label Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Request for a new feature
Projects
None yet
Development

No branches or pull requests

3 participants