title: Multiple esign using pdfbox 2.0.12 java?
body: <p>I was trying to add multiple signatures in a single pdf on stamper. I am able to add multiple stampers. In my case on one, I was getting the error</p>
  <blockquote>
  <p>at least one signature is invalid.
  Also need to make valid all signature.</p>
  </blockquote>
  <p>I want to add multiple valid signs in a single PDF. Please help me.
  In image only one sign is valid other signs are invalid, so let me what I'm doing wrong</p>
  <p>My code snapshot below</p>
  <pre><code>public void getSignOnPdf(Map&lt;Integer, byte[]&gt; PdfSigneture1, List&lt;Long&gt; documentIds, List&lt;String&gt; calTimeStamp,
          String originalPdfReadServerPath, String tickImagePath, int serverTime, int pageNumberToInsertStamp,
          String name, String location, String reasonForSign, int xCo_ordinates, int yCo_ordinates,
          int signatureWidth, int signatureHeight, String pdfPassword, String internal_outputFinalPdfPath)
          throws Exception {
      String pdfReadServerPath = null;
      String l_slash = new String();
      String originalPDFPath = new String(originalPdfReadServerPath.trim());
      
      boolean isCorrectPDFOutputPath = false;
      String aspOutputPdfServerPath = null;
      synchronized (this) {
          if ((internal_outputFinalPdfPath != null) &amp;&amp; (!internal_outputFinalPdfPath.trim().isEmpty())) {
              System.out.println(&quot;[&quot; + EsignCommonFuntion.generateTimeStampForLog()
                      + &quot;] :1--&gt;  outputFinalPdfPath is: &quot; + internal_outputFinalPdfPath);
              if (!(new File(internal_outputFinalPdfPath)).isFile()) {
                  isCorrectPDFOutputPath = true;
                  aspOutputPdfServerPath = internal_outputFinalPdfPath;
              } else {
                  System.out.println(&quot;1--&gt; Please provide directory path for outputFinalPdfPath: &quot;
                          .concat(String.valueOf(internal_outputFinalPdfPath)));
              }
          } else {
              System.out.println(&quot; 1--&gt; outputFinalPdfPath is empty or null: &quot;
                      .concat(String.valueOf(internal_outputFinalPdfPath)));
          }
      }
      boolean isPasswordPresent = false;
      String pdfPasswordForEncryption;
      synchronized (this) {
          if ((pdfPassword != null) &amp;&amp; (!pdfPassword.trim().isEmpty())) {
              pdfPasswordForEncryption = pdfPassword.trim();
              isPasswordPresent = true;
          } else {
              pdfPasswordForEncryption = null;
          }
          String pdfOriginalName = (new File(originalPDFPath)).getName();
          String pdfAbsolutePath = originalPDFPath.substring(0, originalPDFPath.lastIndexOf(l_slash));
          if (isPasswordPresent) {
              pdfAbsolutePath = getEncryptedPdfName(originalPDFPath, pdfAbsolutePath + l_slash,
                      pdfPasswordForEncryption, pdfOriginalName);
              pdfReadServerPath = new String(pdfAbsolutePath);
          } else {
              pdfReadServerPath = originalPDFPath;
          }
      }
      ArrayList&lt;String&gt; unSignedFilesList = new ArrayList&lt;String&gt;();
  
      Map&lt;Integer, byte[]&gt; l_PdfSigneture = PdfSigneture1;
  
      int actual_pageNumForStamp = 1;
  
      String pdfFileName = (new File(pdfReadServerPath)).getName();
  
      FileOutputStream fos = null;
  
      String nameToShowInSignature = name;
      String locationToShowInSignature = location;
      String reasonForSignatureSign = reasonForSign;
  
      PDDocument documentFinal = null;
      try {
          pdfReadServerPath = pdfReadServerPath.substring(0, pdfReadServerPath.lastIndexOf(l_slash));
          System.out.println(&quot;inside getSignOnMethod pdfAbsolutePath:&quot;.concat(String.valueOf(pdfReadServerPath)));
          unSignedFilesList.add(pdfFileName);
          System.out.println(&quot;inside getSignOnMethod pdfFileName:&quot;.concat(String.valueOf(pdfFileName)));
          
          String PDFpath = pdfReadServerPath + l_slash + (String) (unSignedFilesList).get(0);
  
          System.out.println(&quot;Inside for PDFpath: &quot;.concat(String.valueOf(PDFpath)));
  
          String finalOutputPdfName = ((String) (unSignedFilesList).get(0)).substring(0,
                  ((String) (unSignedFilesList).get(0)).lastIndexOf(&quot;.&quot;)) + &quot;_signedFinal.pdf&quot;;
  
          File outFile2 = null;
  
          if (isCorrectPDFOutputPath) {
              System.out.println(&quot;if condition Final signed PDF ouptut Path: &quot; + aspOutputPdfServerPath + l_slash
                      + finalOutputPdfName);
              outFile2 = new File(aspOutputPdfServerPath + l_slash + finalOutputPdfName);
              fos = new FileOutputStream(outFile2);
          } else {
              outFile2 = new File(pdfReadServerPath + l_slash + outFile2);
              fos = new FileOutputStream(outFile2);
          }
  
          documentFinal = PDDocument.load(new File(PDFpath));
              
          for (int i = 1; i &lt; 4; i++) {
              FileInputStream image2 = new FileInputStream(tickImagePath);
              
              PDSignature pdsignature = new PDSignature();
              pdsignature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
              pdsignature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
  
              Calendar cal = GregorianCalendar.getInstance();
              SimpleDateFormat l_simpleDateFormater = new SimpleDateFormat(&quot;yyyyMMdd_HHmmss&quot;);
              String timeStamp = (String) calTimeStamp.get(i - 1);
  
              try {
                  cal.setTime(l_simpleDateFormater.parse(timeStamp));
              } catch (ParseException ex) {
                  ex.printStackTrace();
              }
  
              cal.add(12, serverTime);
              pdsignature.setSignDate(cal);
              documentFinal.setDocumentId((Long) documentIds.get(i - 1));
  
              String dateToShowInSignature = cal.getTime().toString();
              
              Float saveIncrementalObj1 = null;
              saveIncrementalObj1 = new Float((float) xCo_ordinates, (float) yCo_ordinates, (float) signatureWidth,
                      (float) signatureHeight);
  
              PDRectangle rect = getPDRectangle(documentFinal, saveIncrementalObj1, i);
              PDVisibleSignDesigner visibleSig;
              (visibleSig = new PDVisibleSignDesigner(documentFinal, image2, i)).xAxis(xCo_ordinates)
                      .yAxis(yCo_ordinates).zoom(-95.0F).signatureFieldName(&quot;signature&quot;);
              
              PDVisibleSigProperties visibleSignatureProp = new PDVisibleSigProperties();
              
              visibleSignatureProp.signerName(&quot;name&quot;).signerLocation(&quot;location&quot;).signatureReason(&quot;Security&quot;)
                      .preferredSize(0).page(i - 1).visualSignEnabled(true).setPdVisibleSignature(visibleSig)
                      .buildSignature();
              try {
                  PdfSigneture = new TreeMap&lt;&gt;();
                  // PdfSigneture.clear();
                  PdfSigneture = l_PdfSigneture;
                  
                  if (visibleSignatureProp.isVisualSignEnabled()) {
                      this.options = new SignatureOptions();
                      this.options.setVisualSignature(visibleSignatureProp);
                      this.options.setPage(visibleSignatureProp.getPage());
                      this.options.setVisualSignature(
                              getInputStream(documentFinal, i, rect, tickImagePath, nameToShowInSignature,
                                      locationToShowInSignature, dateToShowInSignature, reasonForSignatureSign));
                      documentFinal.addSignature(pdsignature, this, this.options);
                  } else {
                      documentFinal.addSignature(pdsignature, this);
                  }
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
          
          synchronized (this) {
              SaveIncrementalSignObject saveIncrementalSignObject;
              (saveIncrementalSignObject = new SaveIncrementalSignObject()).setFos(fos);
              saveIncrementalSignObject.setPDDocumentFromFile(documentFinal);
              
              saveIncrementalForSign(saveIncrementalSignObject);
          }
      } catch (Exception localException2) {
          System.out.println(&quot;Insidemethod -- Exception block&quot; + localException2.getMessage());
          return;
      } finally {
          fos.flush();
          if (fos != null) {
              fos.close();
          }
          documentFinal.close();
      }
  }
  
  public static synchronized void saveIncrementalForSign(SaveIncrementalSignObject p_SaveIncrementalObj) {
      PDDocument documentFinal = null;
      try {
          (documentFinal = p_SaveIncrementalObj.getPDDocumentFromFile())
                  .saveIncremental(p_SaveIncrementalObj.getFos());
      } catch (Exception e) {
          e.printStackTrace();
          try {
          //              documentFinal.close();
              return;
          } catch (Exception eX) {
              eX.printStackTrace();
              return;
          }
      }
  }
  </code></pre>