Use python module designed for this task, it signs digitally PDF-s.
Everything what You should have is p12/pfx file with certificate.
Simple example in:
github repository example
#!/usr/bin/env python3
# *-* coding: utf-8 *-*
from oscrypto import asymmetric
from endesive import pdf
def main():
dct = {
b'sigflags': 3,
b'contact': b'me@email.com',
b'location': b'City',
b'signingdate': b'20180731082642+02\'00\'',
b'reason': b'Some descriptive message',
}
p12 = asymmetric.load_pkcs12(
open('demo2_user1.p12', 'rb').read(),
'1234'
)
datau = open('pdf.pdf', 'rb').read()
datas = pdf.cms.sign(datau, dct, p12[0], p12[1], [], 'sha256')
with open('pdf-signed-cms.pdf', 'wb') as fp:
fp.write(datau)
fp.write(datas)
main()