title: How to crop the signature from a box in a pdf with imagemagick?
body: <p>I need to extract the box with a hand-written signature from a scanned document.</p>
  
  <p>My PDF looks like this: <a href="https://dl.dropboxusercontent.com/u/1117936/mock.pdf" rel="nofollow noreferrer">Link to Dropbox</a></p>
  
  <p>People will download this, sign it, then upload it back to me. How can I extract the insides of that signature box? (I can modify PDF if needed, add some borders, barcodes, whatever would help.)</p>
  
  <p>I've tried all sorts of imagemagick things. I can get estimated coordinates, something like this:</p>
  
  <pre><code>convert -crop 350x75+180+300 mock.pdf mock.png
  </code></pre>
  
  <p>It gets me close, but not precise(people scan differently). But now I have this extracted signature:</p>
  
  <p><img src="https://i.stack.imgur.com/cnRmS.png" alt="enter image description here"></p>
  
  <p>Now I still don't know how to get into the box and crop only that part. I have tried with some trim and fuzz and even multicrop, but no real results.</p>
  
  <p>Some examples of what I've tried:</p>
  
  <pre><code>convert -fuzz 10% -bordercolor black -border 2x2 -trim +repage
  
  convert -trim
  
  convert -trim +repage
  
  multicrop -f 10% -b black -border 1x1 -trim + repage
  
  multicrop -f 10% -b white -border 1x1 -trim + repage
  </code></pre>
  
  <p>I only got to trim white around my border, but not up to a pixel.</p>
  
  <p>I even tried using tesseract to find the words SIGN HERE, and extract coordinates, and approximate the coordinates from that - but I'm still stuck with the same problem, how to only get the inside of the box.</p>
  
  <p>What else can I try?</p>
  
  <p>I can pipe multiple convert commands in a shell file, no problem there. The background (probably similar to white, depends on the scanning) can be extracted, no problem - in fact, that's the desired efect, to make it transparent in the end, but didn't want to make this a part of the question if it is going to complicate things.</p>
  
  <p>Any examples of what I can try are highly appreciated.</p>