title: Digital PDF Document Signing
body: <h2>Update 2:</h2>
  
  <p>I have uploaded sample at <a href="https://1drv.ms/u/s!Al69FgQ8jwmZbgiBMXLLM4j5sbU?e=vyGF4m" rel="nofollow noreferrer">https://1drv.ms/u/s!Al69FgQ8jwmZbgiBMXLLM4j5sbU?e=vyGF4m</a></p>
  
  <p>Can you please check. I am stuck at last step. However, please confirm if other appraoch is correct. </p>
  
  <h2>Update 1:</h2>
  
  <p>I have confirmed the flow. So I am clear on it. </p>
  
  <p>As part of that digital signing PDF document flow , We want to use third party to provide Signed Hash of PDF.
  Here are steps:</p>
  
  <ol>
  <li>There is 3rd party inhouse system which will generate PDF document from word.</li>
  <li>That PDF will be send to another service which will generate Hash value of that PDF</li>
  <li>That hash value will be send to external service to sing hash with private key. </li>
  <li>external system will send signed hash and public key certiciate using which in house service will add signature in PDF document.</li>
  </ol>
  
  <p>I have following questions.</p>
  
  <ol>
  <li>In point 1 above inhouse service is creating PDF along with signature block . Is it necessary to create signature block? as this is deferred signing?</li>
  <li>If so, how can service in point 2 can get original content of PDF document for generating hash.</li>
  </ol>
  
  <p>we have used existing PDF which has signature and using iText 7 to get original content. 
  Is this method correct?
  FormB.PDF has signature and by removing signaure1 field we are getting original content. Will this process work and advistable?</p>
  
  <p>We also tried to use pdfsigner.getRangeStream() method, but its not that clear in documentation and not yet clear. Please help</p>
  
  <pre><code>package com.abc.sd;
  
  import java.io.IOException;
  import java.security.NoSuchAlgorithmException;
  import java.util.List;
  
  import com.itextpdf.forms.PdfAcroForm;
  import com.itextpdf.kernel.pdf.PdfDocument;
  import com.itextpdf.kernel.pdf.PdfReader;
  import com.itextpdf.kernel.pdf.PdfWriter;
  import com.itextpdf.signatures.SignatureUtil;
  
  public class ItextPdf7 {
  
      public static void main(String [] args) throws IOException, NoSuchAlgorithmException {
          String filePath ="C:\\\\abc\\\\test\\\\FormB.pdf";
          PdfReader reader = new PdfReader(filePath);
          PdfDocument pdfDoc = new PdfDocument(reader);
          PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, false);
          SignatureUtil signUtil = new SignatureUtil(pdfDoc);
          List&lt;String&gt; names = signUtil.getSignatureNames();
          System.out.println("Signature Name&gt;&gt;&gt;"+names);
        //  System.out.println("Singature Data&gt;&gt;"+signUtil.readSignatureData("Signature1"));
  
  
          PdfReader reader1 = new PdfReader(filePath);
          PdfDocument pdfDoc1 = new PdfDocument(reader1, new PdfWriter("C:\\\\\\\\abc\\\\\\\\test\\\\\\\\unsigned_latest_iext7.pdf"));
          PdfAcroForm form1 = PdfAcroForm.getAcroForm(pdfDoc1, true);
          form1.flattenFields();
          pdfDoc1.close();
  
  
      }
  
  }
  
  </code></pre>
  
  <h2>******************************</h2>
  
  <p>We are looking to <strong>sign PDF document</strong>.  here are steps as per my understanding.</p>
  
  <ol>
  <li><p>      Consumer will send a digest of PDF document to Central System. 
        The digest of the PDF will exclude the signature section </p></li>
  <li><p>      Central System will send the digest  (signed using consumer’s private key/public key ? not sure)  to consumer</p></li>
  <li><p>      consumer system will add digest within in the signature section the PDF document (may be along with public key ??)</p></li>
  </ol>
  
  <p>Can you please help on following.</p>
  
  <ol>
  <li><p>If my understanding is correct with above flow? Any small reference guide / link will help or any flow diagram.</p></li>
  <li><p>With .Net and Java what are libraries which can do this work ?Both open source and paid. Will iTextSharp is relevant here?</p></li>
  <li><p>How validation will happen if customer opens the PDF? If there any specific action required document signing?</p></li>
  </ol>
  
  <p>Plz help.</p>