title: ITextSharp signing PDF/A document
body: <p>So I am trying to sign a PDF/A-1A document, the document was generated using ITextSharp. When i Sign the document and try to verify the document i get the following errors,</p>
  
  <blockquote>
    <p>Validating file "test_pdfA_compliance_signed.pdf" for conformance level pdfa-1a
    The required XMP property 'pdfaid:part' is missing.
    The required XMP property 'pdfaid:conformance' is missing.
    A string is longer than 65535 bytes.
    The document does not conform to the requested standard.
    The document doesn't conform to the PDF reference (missing required entries, wrong value types, etc.).
    The document's meta data is either missing or inconsistent or corrupt.
    Done.</p>
  </blockquote>
  
  <p>Document Pre-Signed: <a href="https://drive.google.com/file/d/0B9RyqgJoa6W8UDFSeHJSX09QamM/view?usp=sharing" rel="nofollow">https://drive.google.com/file/d/0B9RyqgJoa6W8UDFSeHJSX09QamM/view?usp=sharing</a></p>
  
  <p>Document Post-Signed: <a href="https://drive.google.com/file/d/0B9RyqgJoa6W8Y3lGbFU4a2RsLWc/view?usp=sharing" rel="nofollow">https://drive.google.com/file/d/0B9RyqgJoa6W8Y3lGbFU4a2RsLWc/view?usp=sharing</a></p>
  
  <p>But the signing process is completed as expected, but what i have realised was that if I test whether the document claims to be PDF/A compliant it fails as if there is not metadata claiming PDF/A,</p>
  
  <pre><code>private bool CreatePdfStamperIsPDFADocument(PdfReader reader)
      {
          if (reader.Metadata != null &amp;&amp; reader.Metadata.Length &gt; 0)
          {
              IXmpMeta xmpMeta = XmpMetaParser.Parse(reader.Metadata, null);
              IXmpProperty pdfaidConformance = xmpMeta.GetProperty(XmpConst.NS_PDFA_ID, "pdfaid:conformance");
              IXmpProperty pdfaidPart = xmpMeta.GetProperty(XmpConst.NS_PDFA_ID, "pdfaid:part");
  
              if (pdfaidConformance == null || pdfaidPart == null)
              {
                  return false;
              }
          }
  
          return true;
      }
  </code></pre>
  
  <p>The code i used to sign the document, the PDF stamper used here is the normal one since the check fails. When i try to use the PDFAStamper it complains saying that only PDF/A documents can be used.</p>
  
  <pre><code>private byte[] SignDocument(Certificate certificate, SigningInformation information, List&lt;SigningBlock&gt; signingBlocks, List&lt;MemberItemSignature&gt; signatureImages, byte[] document, bool certify)
      {
          for (int i = 0; i &lt; signingBlocks.Count; i++)
          {
              using (MemoryStream outputStream = new MemoryStream())
              {
                  using (PdfReader reader = new PdfReader(document))
                  {
                      using (PdfStamper stamper = CreatePdfStamper(reader, outputStream, true))
                      {
                          SigningBlock signingBlock = signingBlocks[i];
                          PdfSignatureAppearance appearance = CreatePdfAppearance(stamper, information, certify &amp;&amp; i == 0);
  
                          SignDocumentSigningBlock(certificate, information, signingBlock, appearance, stamper, GetSignatureImage(signatureImages, signingBlock.Name));
                      }
                  }
  
                  document = outputStream.ToArray();
              }
          }
  
          return document;
      }
  </code></pre>
  
  <p>So this is the code where i determine which PDF stamper to use, but this is where it fails since the document im using is returning null for both components I use to determine PDF/A claim,</p>
  
  <pre><code>        private PdfStamper CreatePdfStamper(PdfReader reader, MemoryStream outputStream, bool isSignature)
      {
          if (isSignature)
          {
              if (CreatePdfStamperIsPDFADocument(reader))
              {
                  return PdfAStamper.CreateSignature(reader, outputStream, _pdfVersion, null, true, PdfAConformanceLevel.PDF_A_1A);
              }
              else
              {
                  return PdfStamper.CreateSignature(reader, outputStream, _pdfVersion, null, true);
              }
          }
          else
          {
              return new PdfStamper(reader, outputStream, _pdfVersion, true);
          }
      }
  </code></pre>
  
  <p>Am I doing something stupid or missing something small?
  Thank you for any help.</p>
  
  <p>Kind regards</p>