Lo que quiero hacer, una vez firmado con un certificado el pdf, protegerlo para que no puedan imprimirlo, ni copiar contenido, ni volver a firmarlo. He probado con :
PdfEncryptor.Encrypt(
reader,
new FileStream(this.outputPDF, FileMode.Create, FileAccess.Write),
true,
null,
null,
PdfWriter.AllowFillIn | PdfWriter.AllowScreenReaders);
El error que me da son estos dos:
iTextSharp.text.DocumentException: 'The original document was reused. Read it again from file.' System.IO.IOException: 'The process can not access the file 'C:\Users\User\Desktop\test.pdf'
Para firmar uso:
public void Sign(string SigReason, string SigContact, string SigLocation, bool visible)
{
PdfReader reader = new PdfReader(this.inputPDF);
/*ERROR-->*/PdfEncryptor.Encrypt(reader, new FileStream(this.outputPDF, FileMode.Create, FileAccess.Write), true, null, null, PdfWriter.AllowFillIn | PdfWriter.AllowScreenReaders);
PdfStamper st = PdfStamper.CreateSignature(reader, new FileStream(this.outputPDF, FileMode.Create, FileAccess.Write), '\0', null, true);
st.MoreInfo = this.metadata.getMetaData();
st.XmpMetadata = this.metadata.getStreamedMetaData();
PdfSignatureAppearance sap = st.SignatureAppearance;
sap.SetCrypto(this.myCert.Akp, this.myCert.Chain, null, PdfSignatureAppearance.WINCER_SIGNED);
sap.Reason = SigReason;
sap.Contact = SigContact;
sap.Location = SigLocation;
if (visible)
sap.SetVisibleSignature(new iTextSharp.text.Rectangle(100, 100, 250, 150), 1, null);
st.Close();
}
System.IO.IOException: 'El proceso no puede obtener acceso al archivo 'C:\Users\Usuario\Desktop\PRUEBA CERT_firmado.pdf' porque está siendo utilizado en otro proceso.'