Let’s consider the case where the signed document is a pdf (document.pdf.p7m).
To extract the content file we use the openssl command with the smime parameter for signature verification (-verify)
From Extracting the contents of a digitally signed file (p7m) – Quoll techopenssl smime -verify -noverify -in document.pdf.p7m -inform DER -out document.pdf