Commit b9d9540f authored by Jérome Perrin's avatar Jérome Perrin

pdf: use pypdf >= 3.6.0

parent ff27e154
...@@ -36,11 +36,13 @@ from cloudooo.util import logger, parseContentType ...@@ -36,11 +36,13 @@ from cloudooo.util import logger, parseContentType
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from tempfile import mktemp from tempfile import mktemp
from pyPdf import PdfFileWriter, PdfFileReader
from pyPdf.generic import NameObject, createStringObject from pypdf import PdfWriter, PdfReader
from pypdf.generic import NameObject, createStringObject
@implementer(IHandler) @implementer(IHandler)
class Handler(object): class Handler:
"""PDF Handler is used to handler inputed pdf document.""" """PDF Handler is used to handler inputed pdf document."""
def __init__(self, base_folder_url, data, source_format, **kw): def __init__(self, base_folder_url, data, source_format, **kw):
...@@ -94,8 +96,8 @@ class Handler(object): ...@@ -94,8 +96,8 @@ class Handler(object):
metadata -- expected an dictionary with metadata. metadata -- expected an dictionary with metadata.
""" """
# TODO: date as "D:20090401124817-04'00'" ASN.1 for ModDate and CreationDate # TODO: date as "D:20090401124817-04'00'" ASN.1 for ModDate and CreationDate
input_pdf = PdfFileReader(open(self.document.getUrl(), "rb")) input_pdf = PdfReader(self.document.getUrl())
output_pdf = PdfFileWriter() output_pdf = PdfWriter()
modification_date = metadata.pop("ModificationDate", None) modification_date = metadata.pop("ModificationDate", None)
if modification_date: if modification_date:
...@@ -103,13 +105,13 @@ class Handler(object): ...@@ -103,13 +105,13 @@ class Handler(object):
if type(metadata.get('Keywords', None)) is list: if type(metadata.get('Keywords', None)) is list:
metadata['Keywords'] = metadata['Keywords'].join(' ') metadata['Keywords'] = metadata['Keywords'].join(' ')
args = {} args = {}
for key, value in list(metadata.items()): for key, value in metadata.items():
args[NameObject('/' + key.capitalize())] = createStringObject(value) args[NameObject('/' + key.capitalize())] = createStringObject(value)
output_pdf._info.getObject().update(args) output_pdf._info.get_object().update(args)
for page_num in range(input_pdf.getNumPages()): for page in input_pdf.pages:
output_pdf.addPage(input_pdf.getPage(page_num)) output_pdf.add_page(page)
output_stream = io.BytesIO() output_stream = io.BytesIO()
output_pdf.write(output_stream) output_pdf.write(output_stream)
......
...@@ -12,7 +12,7 @@ install_requires = [ ...@@ -12,7 +12,7 @@ install_requires = [
'zope.interface', 'zope.interface',
'PasteDeploy', 'PasteDeploy',
'PasteScript[WSGIUtils]', 'PasteScript[WSGIUtils]',
'pyPdf', 'pyPdf>=3.6.0',
'psutil>=3.0.0', 'psutil>=3.0.0',
'lxml', 'lxml',
'python-magic', 'python-magic',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment