Monday, October 8, 2012

Scanned in jpg's converted to one pdf file.

Simple method for taking a bunch of scanned in jpeg files and making one paged pdf file.

for i in $(ls ~/Directory/*.jpg); do convert -verbose $i $(basename ${i%.jpg}).pdf ; done;

The above converts all jpegs into individual pdf pages.  Convert will connect them together for you, but unless you have a huge amount of memory it will fail.

pdftk *.pdf cat output newdoc.pdf

The above here combines all of the pdf pages into one document.  Instead of using wildcard you could take the time to arrange the pages as you see fit.

Thursday, September 20, 2012

Python!  Well its an easy language to learn.  I want to master it, so I'm making myself commit to at least three random that may or may not be useful, python tools a week.  This to keep my python skill sharp, and I will post my discoveries here.

The script grabs a url of unconditional file type to a file.

#!/usr/bin/python
# grabs a url to a file.

import sys
import urllib2
from os.path import basename
from urlparse import urlsplit

if len(sys.argv) < 2:
  print "Usage: %s <URL>" % sys.argv[0]
  sys.exit()

url = sys.argv[1]
urlContent = urllib2.urlopen(url).read()
fileName = basename(urlsplit(url)[2])
print "filename is: %s" % fileName
output = open(fileName,'wb')
output.write(urlContent)
output.close()

Trying to keep it simple as possible with minimal error checking.  You can add your own if you use the code.