title: Visual signature with pdfbox 1.8.8
body: <p>I'm trying to produce PDF with visual signature and pdfbox. I have two streams and it seems that pdfbox can deal only with files. I didn't manage to make it work without three temporary files. I can see from <a href="https://github.com/apache/pdfbox/blob/b789c91d57f4a3b8763b35779309ea422db66c5d/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java" rel="noreferrer">here</a> that API has changed, but still it deals with files.</p>
  
  <pre><code>public void signPdf(InputStream originalPdf, OutputStream signedPdf,
          InputStream image, float x, float y,
          String name, String location, String reason) {
  
      File temp = null;
      File temp2 = null;
      File scratchFile = null;
      RandomAccessFile randomAccessFile = null;
      OutputStream tempOut = null;
      InputStream tempIn = null;
      try {
          /* Copy original to temporary file */
          temp = File.createTempFile("signed1", ".tmp");
          tempOut = new FileOutputStream(temp);
          copyStream(originalPdf, tempOut);
          tempOut.close();
  
          /* Read temporary file to second temporary file and stream */
          tempIn = new FileInputStream(temp);
          temp2 = File.createTempFile("signed2", ".tmp");
          tempOut = new FileOutputStream(temp2);
          copyStream(tempIn, tempOut);
          tempIn.close();
          tempIn = new FileInputStream(temp2);
  
          scratchFile = File.createTempFile("signed3", ".bin");
          randomAccessFile = new RandomAccessFile(scratchFile, "rw");
  
          /* Read temporary file */
          PDDocument document = PDDocument.load(temp, randomAccessFile);
          document.getCurrentAccessPermission().setCanModify(false);
  
          PDSignature signature = new PDSignature();
          signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
          signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
          signature.setName(name);
          signature.setLocation(location);
          signature.setReason(reason);
          signature.setSignDate(Calendar.getInstance());
  
          PDVisibleSignDesigner signatureDesigner = new PDVisibleSignDesigner(
                  document, image, document.getNumberOfPages());
          signatureDesigner.xAxis(250).yAxis(60).zoom(-90).signatureFieldName("signature");
  
          PDVisibleSigProperties signatureProperties = new PDVisibleSigProperties();
          signatureProperties.signerName(name).signerLocation(location)
                  .signatureReason(reason).preferredSize(0).page(1)
                  .visualSignEnabled(true).setPdVisibleSignature(signatureDesigner)
                  .buildSignature();
  
          SignatureOptions options = new SignatureOptions();
          options.setVisualSignature(signatureProperties);
  
          document.addSignature(signature, dataSigner, options);
  
          /* Sign */
          document.saveIncremental(tempIn, tempOut);
          document.close();
          tempIn.close();
  
          /* Copy temporary file to an output stream */
          tempIn = new FileInputStream(temp2);
          copyStream(tempIn, signedPdf);
      } catch (IOException e) {
          logger.error("PDF signing failure", e);
      } catch (COSVisitorException e) {
          logger.error("PDF creation failure", e);
      } catch (SignatureException e) {
          logger.error("PDF signing failure", e);
      } finally {
          closeStream(originalPdf);
          closeStream(signedPdf);
          closeStream(randomAccessFile);
          closeStream(tempOut);
          deleteTempFile(temp);
          deleteTempFile(temp2);
          deleteTempFile(scratchFile);
      }
  }
  
  private void deleteTempFile(File tempFile) {
      if (tempFile != null &amp;&amp; tempFile.exists() &amp;&amp; !tempFile.delete()) {
          tempFile.deleteOnExit();
      }
  }
  
  private void closeStream(Closeable is) {
      if (is!= null) {
          try {
              is.close();
          } catch (IOException e) {
              logger.error("failure", e);
          }
      }
  }
  
  private void copyStream(InputStream is, OutputStream os) throws IOException {
      byte[] buffer = new byte[1024];
      int c;
      while ((c = is.read(buffer)) != -1) {
          os.write(buffer, 0, c);
      }
      is.close();
  }
  </code></pre>
  
  <p>Apart from file madness I don't see any text on the signature. This is how result looks like:</p>
  
  <p><img src="https://i.stack.imgur.com/gQuuk.png" alt="enter image description here"></p>
  
  <p>and this is how it looks, when I do similar thing with itext library</p>
  
  <p><img src="https://i.stack.imgur.com/2tUqS.png" alt="enter image description here"></p>
  
  <p>Why name, location and reason missing from the visual signature representation? How can I fix that?</p>