title: JAVA - How to create signed PDF using original PDF and separate PKCS#7 signed data
body: <p>I have a original PDF document and separate file as PKCS#7 signed data.
  I would like to combine these to create signed PDF document so that it could be shown in for example Adobe reader that it is signed and who signed the document.</p>
  
  <p>Are there any libraries in Java that could be used to create such signed PDF document programatically? I need to load that PDF and add the signature to it somehow, then save it as a new PDF document. </p>
  
  <p>Sample code would be appreciated.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The resulting code should take the PDF document as input parameter and do the following:</p>
  
  <ol>
  <li>prepare data to be signed</li>
  <li>provide data to be signed to external signing mechanism that produces PKCS#7 signed data file</li>
  <li>provide PKCS#7 signed data file</li>
  <li>add signed data to PDF document</li>
  <li>save PDF document</li>
  </ol>
  
  <p>As I understand the first step is important because without that the PKCS#7 signed data would be wrong.</p>