Let's consider the case where the signed document is a pdf (document.pdf.p7m).
To extract the certificate used to sign the p7m we use the openssl command with the pkcs parameter
openssl pkcs7 -inform DER -in document.pdf.p7m -print_certs -out cert.pem
The certificate will be extracted in the cert.pem file. If you want to display textually enough the certificate command x509
openssl x509 -in cert.pem -text -noout
For more information, see the articol