public void ApplySignature(Stream pdfStreamOutput)
{
if (DocumentSecurity == null) return;
if (DocumentSecurity.DigitalSignature == null) return;
if (DocumentSecurity.EncryptionPreferences == null) return;
// close the document without closing the underlying stream
PdfWriter.CloseStream = false;
PdfDoc.Close();
pdfStreamOutput.Position = 0;
signPasswordEncryption(pdfStreamOutput);
signPublicKeyEncryption(pdfStreamOutput);
}