caerp-sign-pdf 2024.1.1__tar.gz → 2024.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- caerp_sign_pdf-2024.1.2/CURRENT_VERSION +1 -0
- {caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/PKG-INFO +1 -1
- caerp_sign_pdf-2024.1.2/requirements.txt +1 -0
- {caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/src/caerp_sign_pdf/public.py +27 -5
- {caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/src/caerp_sign_pdf.egg-info/PKG-INFO +1 -1
- caerp_sign_pdf-2024.1.2/src/caerp_sign_pdf.egg-info/requires.txt +1 -0
- caerp_sign_pdf-2024.1.1/CURRENT_VERSION +0 -1
- caerp_sign_pdf-2024.1.1/requirements.txt +0 -1
- caerp_sign_pdf-2024.1.1/src/caerp_sign_pdf.egg-info/requires.txt +0 -1
- {caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/LICENSE.txt +0 -0
- {caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/MANIFEST.in +0 -0
- {caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/README.rst +0 -0
- {caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/setup.cfg +0 -0
- {caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/setup.py +0 -0
- {caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/src/caerp_sign_pdf/__init__.py +0 -0
- {caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/src/caerp_sign_pdf/models.py +0 -0
- {caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/src/caerp_sign_pdf.egg-info/SOURCES.txt +0 -0
- {caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/src/caerp_sign_pdf.egg-info/dependency_links.txt +0 -0
- {caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/src/caerp_sign_pdf.egg-info/not-zip-safe +0 -0
- {caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/src/caerp_sign_pdf.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2024.1.2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pyHanko[pkcs11,image-support,opentype,xmp]==0.25.0
|
|
@@ -4,12 +4,11 @@ import hashlib
|
|
|
4
4
|
|
|
5
5
|
from io import BytesIO
|
|
6
6
|
from pyhanko.pdf_utils.incremental_writer import IncrementalPdfFileWriter
|
|
7
|
-
from pyhanko.sign import
|
|
8
|
-
fields,
|
|
9
|
-
signers,
|
|
10
|
-
)
|
|
7
|
+
from pyhanko.sign import fields, signers
|
|
11
8
|
from pyhanko.sign.general import SigningError
|
|
12
9
|
from pyhanko.stamp import TextStampStyle
|
|
10
|
+
from PyPDF4.pdf import PdfFileReader, PdfFileWriter, utils
|
|
11
|
+
from pyramid.httpexceptions import HTTPInternalServerError
|
|
13
12
|
|
|
14
13
|
from caerp.views.files.controller import FileData
|
|
15
14
|
|
|
@@ -51,6 +50,19 @@ class SignPDFService(object):
|
|
|
51
50
|
"""
|
|
52
51
|
return hashlib.md5(file_data.getvalue()).hexdigest()
|
|
53
52
|
|
|
53
|
+
def _get_safe_pdf(self, file_data: BytesIO) -> str:
|
|
54
|
+
"""
|
|
55
|
+
Create a new clean PDF buffer from the original
|
|
56
|
+
to avoid some format errors
|
|
57
|
+
"""
|
|
58
|
+
writer = PdfFileWriter()
|
|
59
|
+
reader = PdfFileReader(file_data, strict=False)
|
|
60
|
+
num_pages = reader.getNumPages()
|
|
61
|
+
for page in range(num_pages):
|
|
62
|
+
writer.addPage(reader.getPage(page))
|
|
63
|
+
writer.write(file_data)
|
|
64
|
+
return file_data
|
|
65
|
+
|
|
54
66
|
def sign(
|
|
55
67
|
self, pdf_data: FileData, node_id: int = None, with_stamp: bool = False
|
|
56
68
|
) -> bool:
|
|
@@ -97,7 +109,17 @@ in config)"
|
|
|
97
109
|
border_width=0,
|
|
98
110
|
)
|
|
99
111
|
|
|
100
|
-
#
|
|
112
|
+
# Clean PDF before signing
|
|
113
|
+
try:
|
|
114
|
+
pdf_data.data = self._get_safe_pdf(pdf_data.data)
|
|
115
|
+
except Exception as error:
|
|
116
|
+
logger.error(f"Unknown error while cleaning original PDF file : {error}")
|
|
117
|
+
raise HTTPInternalServerError(
|
|
118
|
+
"Le fichier PDF ne peut pas être traité car son format n'est pas \
|
|
119
|
+
correct. Vous pouvez essayer de le réimprimer dans un nouveau fichier PDF."
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
# Sign PDF
|
|
101
123
|
w = IncrementalPdfFileWriter(pdf_data.data, strict=False)
|
|
102
124
|
try:
|
|
103
125
|
fields.append_signature_field(
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pyHanko[image-support,opentype,pkcs11,xmp]==0.25.0
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2024.1.1
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
pyHanko[pkcs11,image-support,opentype,xmp]==0.20.1
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
pyHanko[image-support,opentype,pkcs11,xmp]==0.20.1
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/src/caerp_sign_pdf.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/src/caerp_sign_pdf.egg-info/not-zip-safe
RENAMED
|
File without changes
|
{caerp_sign_pdf-2024.1.1 → caerp_sign_pdf-2024.1.2}/src/caerp_sign_pdf.egg-info/top_level.txt
RENAMED
|
File without changes
|