1

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();

            }
5
  • te sugiero revisar esto: stackoverflow.com/questions/1936189/… el 23 abr. 2019 a las 18:20
  • Buenas Diego, he probado pero me lanza el error: 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.'
    – JoseLuis
    el 23 abr. 2019 a las 19:22
  • verifica que dicho archivo "CERT_firmado.pdf" no este abierto en ningun otro lado..!! el 23 abr. 2019 a las 19:38
  • No lo tengo abierto, fíjate en el código que es el archivo que se crea para firmarlo, supongo que por eso no deja darle los permisos... La idea principal es firmar digitalmente el pdf y quitarle permisos de imprimir, copiar o refirmar. gracias.
    – JoseLuis
    el 23 abr. 2019 a las 19:45
  • tengo el mismo problema. ¿Lo pudiste resolver? el 30 ago. 2021 a las 15:45

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.