Last active
March 25, 2017 22:03
-
-
Save niqdev/67ca957e359d71734be9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
""" | |
sudo easy_install pip | |
pip search pypdf | |
sudo pip install PyPDF2 | |
chmod u+x pdf_meta.py | |
python pdf_meta.py | |
""" | |
from PyPDF2 import PdfFileReader, PdfFileMerger | |
FILE_NAME = '' | |
def read_metadata(name): | |
inputPdf = PdfFileReader(open('%s.pdf' % name, 'rb')) | |
print inputPdf.getDocumentInfo() | |
def edit_metadata(name, data): | |
merger = PdfFileMerger() | |
with open('%s.pdf' % name, 'rb') as f0: | |
merger.append(f0) | |
merger.addMetadata(data) | |
with open('%s_meta.pdf' % name, 'wb') as f1: | |
merger.write(f1) | |
read_metadata(FILE_NAME) | |
metadata = {u'/who':'niqdev', '/Producer': u'recudroP/'} | |
edit_metadata(FILE_NAME, metadata) | |
read_metadata('%s_meta' % FILE_NAME) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment