Error compiling project with itextsharp

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Error compiling project with itextsharp

lucas_max
Hi guys

Im working in a project in C# to sign pdf files using itextsharp.

I have never use itextsharp, so Im following the code of  this page this page 

I have downloaded the last version of iTextsharp (version 5.5.8), but when I compile the code I get many errors because some elements are not recognized. For example,

////////////////////////////////////////////// CODE //////////////////////////////////////////////
...
 var reader = new PdfReader(pdfData);
 var stp = PdfStamper.CreateSignature(reader, stream, '\0');
 var sap = stp.SignatureAppearance;

 //Protect certain features of the document
 stp.SetEncryption(null,
                          Guid.NewGuid().ToByteArray(), //random password
                          PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_COPY |
                          PdfWriter.ALLOW_SCREENREADERS,
                          PdfWriter.ENCRYPTION_AES_256);

 //Get certificate chain
 var cp = new Org.BouncyCastle.X509.X509CertificateParser();
 var certChain = new Org.BouncyCastle.X509.X509Certificate[] { cp.ReadCertificate(cert.RawData) };

 sap.SetCrypto(null, certChain, null, PdfSignatureAppearance.WINCER_SIGNED);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

In the last line I get the error
"itextsharp text pdf pdfsignatureappearance does not have a definition for 'WINCER_SIGNED' "
"itextsharp text pdf pdfsignatureappearance does not have a definition for 'setcrypto' "


In this other chunk of code

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Instantiate SignedCms object with the ContentInfo above.
    //Has default SubjectIdentifierType IssuerAndSerialNumber.
    SignedCms signedCms = new SignedCms(contentInfo, detached);
 
    //Formulate a CmsSigner object for the signer.
    CmsSigner cmsSigner = new CmsSigner(cert);  //First cert in the chain is the signer cert
 
    //Do the whole certificate chain. This way intermediate certificates get sent across as well.
    cmsSigner.IncludeOption = X509IncludeOption.ExcludeRoot;
 
    //Sign the CMS/PKCS #7 message. The second argument is needed to ask for the pin.
    signedCms.ComputeSignature(cmsSigner, false);
/////////////////////////////////////////////////////////////////////////////////////////////////////////

it is not possible to find the class for SignedCms and CmsSigner


The question is: why the compiler says that is not possible to get a definition for that objects even when Im including the respectives DLL's?

Im including this references in my project
-itextsharp
-itextsharp.pdfa
-itextsharp.xtra

and this headers
-using iTextSharp.text;
-using iTextSharp.text.pdf;
-using Org.BouncyCastle.Crypto;
-using Org.BouncyCastle.Pkcs;
-using System.Security.Cryptography.Pkcs;
-using System.Security.Cryptography;

Any help is welcome

Thankyou very much