caerp-sign-pdf 2024.1.2__tar.gz → 2024.1.3__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.3/CURRENT_VERSION +1 -0
- {caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/PKG-INFO +1 -1
- {caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/src/caerp_sign_pdf/public.py +32 -21
- {caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/src/caerp_sign_pdf.egg-info/PKG-INFO +1 -1
- caerp_sign_pdf-2024.1.2/CURRENT_VERSION +0 -1
- {caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/LICENSE.txt +0 -0
- {caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/MANIFEST.in +0 -0
- {caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/README.rst +0 -0
- {caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/requirements.txt +0 -0
- {caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/setup.cfg +0 -0
- {caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/setup.py +0 -0
- {caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/src/caerp_sign_pdf/__init__.py +0 -0
- {caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/src/caerp_sign_pdf/models.py +0 -0
- {caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/src/caerp_sign_pdf.egg-info/SOURCES.txt +0 -0
- {caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/src/caerp_sign_pdf.egg-info/dependency_links.txt +0 -0
- {caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/src/caerp_sign_pdf.egg-info/not-zip-safe +0 -0
- {caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/src/caerp_sign_pdf.egg-info/requires.txt +0 -0
- {caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/src/caerp_sign_pdf.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2024.1.3
|
|
@@ -7,8 +7,8 @@ from pyhanko.pdf_utils.incremental_writer import IncrementalPdfFileWriter
|
|
|
7
7
|
from pyhanko.sign import fields, signers
|
|
8
8
|
from pyhanko.sign.general import SigningError
|
|
9
9
|
from pyhanko.stamp import TextStampStyle
|
|
10
|
-
from PyPDF4.pdf import PdfFileReader, PdfFileWriter
|
|
11
|
-
from pyramid.httpexceptions import
|
|
10
|
+
from PyPDF4.pdf import PdfFileReader, PdfFileWriter
|
|
11
|
+
from pyramid.httpexceptions import HTTPUnsupportedMediaType
|
|
12
12
|
|
|
13
13
|
from caerp.views.files.controller import FileData
|
|
14
14
|
|
|
@@ -18,6 +18,14 @@ from .models import PDFSignatureHistory
|
|
|
18
18
|
logger = logging.getLogger(f"caerp.{__name__}")
|
|
19
19
|
|
|
20
20
|
|
|
21
|
+
ERROR_LOAD_CERTIFICATE_MSG = "Impossible de charger le certificat à utiliser \
|
|
22
|
+
pour signer numériquement le fichier. Veuillez contacter le support."
|
|
23
|
+
|
|
24
|
+
ERROR_PDF_FORMAT_MSG = "Le fichier PDF ne peut pas être signé numériquement \
|
|
25
|
+
car son format n'est pas correct. Vous pouvez essayer de l'imprimer dans un \
|
|
26
|
+
nouveau fichier PDF avant de le recharger."
|
|
27
|
+
|
|
28
|
+
|
|
21
29
|
class SignPDFService(object):
|
|
22
30
|
def __init__(self, context, request):
|
|
23
31
|
self.context = context
|
|
@@ -89,11 +97,11 @@ class SignPDFService(object):
|
|
|
89
97
|
passphrase=self._get_certificate_passphrase().encode(),
|
|
90
98
|
)
|
|
91
99
|
if not signer:
|
|
92
|
-
|
|
100
|
+
logger.error(
|
|
93
101
|
"Unable to load certificate for signing PDF files (check \
|
|
94
|
-
'caerp.sign_certificate_path' and 'caerp.sign_certificate_passphrase'
|
|
95
|
-
in config)"
|
|
102
|
+
'caerp.sign_certificate_path' and 'caerp.sign_certificate_passphrase' in config)"
|
|
96
103
|
)
|
|
104
|
+
raise Exception(ERROR_LOAD_CERTIFICATE_MSG)
|
|
97
105
|
|
|
98
106
|
# Prepare stamp (if needed)
|
|
99
107
|
stamp = None
|
|
@@ -109,21 +117,18 @@ in config)"
|
|
|
109
117
|
border_width=0,
|
|
110
118
|
)
|
|
111
119
|
|
|
112
|
-
#
|
|
120
|
+
# Open original PDF
|
|
113
121
|
try:
|
|
114
122
|
pdf_data.data = self._get_safe_pdf(pdf_data.data)
|
|
123
|
+
pdf_writer = IncrementalPdfFileWriter(pdf_data.data, strict=False)
|
|
115
124
|
except Exception as error:
|
|
116
|
-
logger.error(f"
|
|
117
|
-
raise
|
|
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
|
-
)
|
|
125
|
+
logger.error(f"Error while opening original PDF file : {error}")
|
|
126
|
+
raise HTTPUnsupportedMediaType(ERROR_PDF_FORMAT_MSG)
|
|
121
127
|
|
|
122
|
-
#
|
|
123
|
-
w = IncrementalPdfFileWriter(pdf_data.data, strict=False)
|
|
128
|
+
# Add signature field on the PDF
|
|
124
129
|
try:
|
|
125
130
|
fields.append_signature_field(
|
|
126
|
-
|
|
131
|
+
pdf_writer,
|
|
127
132
|
sig_field_spec=fields.SigFieldSpec(
|
|
128
133
|
"SignatureCAERP", box=(445, 800, 580, 830)
|
|
129
134
|
),
|
|
@@ -131,13 +136,19 @@ correct. Vous pouvez essayer de le réimprimer dans un nouveau fichier PDF."
|
|
|
131
136
|
except SigningError:
|
|
132
137
|
logger.warn("File is already signed, nothing to do")
|
|
133
138
|
return True
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
|
|
140
|
+
# Sign PDF
|
|
141
|
+
try:
|
|
142
|
+
meta = signers.PdfSignatureMetadata(field_name="SignatureCAERP")
|
|
143
|
+
pdf_signer = signers.PdfSigner(
|
|
144
|
+
meta,
|
|
145
|
+
signer=signer,
|
|
146
|
+
stamp_style=stamp,
|
|
147
|
+
)
|
|
148
|
+
pdf_data.data = pdf_signer.sign_pdf(pdf_writer)
|
|
149
|
+
except Exception as error:
|
|
150
|
+
logger.error(f"Error while signing PDF file : {error}")
|
|
151
|
+
raise HTTPUnsupportedMediaType(ERROR_PDF_FORMAT_MSG)
|
|
141
152
|
logger.info(
|
|
142
153
|
"File '{}' signed successfully by {} !".format(
|
|
143
154
|
pdf_data.name, signer.subject_name
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2024.1.2
|
|
File without changes
|
|
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.2 → caerp_sign_pdf-2024.1.3}/src/caerp_sign_pdf.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/src/caerp_sign_pdf.egg-info/not-zip-safe
RENAMED
|
File without changes
|
{caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/src/caerp_sign_pdf.egg-info/requires.txt
RENAMED
|
File without changes
|
{caerp_sign_pdf-2024.1.2 → caerp_sign_pdf-2024.1.3}/src/caerp_sign_pdf.egg-info/top_level.txt
RENAMED
|
File without changes
|