While there are numerous ways to slice this tomato my situation was particularly unique and required an equally unique solution. As many of the long time readers are already aware I spend considerable amounts of tie traveling abroad on business. As exciting as my adventures may sound they do come at a price in the form of the dreaded corporate expense report.
For those of you who have never experienced the pleasure of completing a travel expense report let me step off on this tangent for a moment. In my personal opinion a home root canal performed with a soup spoon would less painful than completing one of these reports.
Imagine if you will being on the road for six weeks or more having to not only log but scan a copy of every receipt for every transaction. To make matters a little more difficult I frequently travel to countries where receipts are an exception. What I mean is if you do not ask for one then you will not get one. In fact more often than not the establishment may not even have the ability to furnish a receipt at all but that is a topic for another time.
At the end of this trip I had hundreds of receipts for things like hotels, meals, taxis, restrooms even clothing. All of these were scanned in during the course of the journey so as to prevent accidental loss. The big problem with this is the bean counters want everything in one complete PDF. This is not without it’s trouble because the corporate email system has a bizarre limit of 5MB for message plus attachments. Even with the receipts squeezed tightly into many pages the size begins to add up.
So my problem was how to combine all of the individual PDF documents into one file without having Adobe Accrobat Professional on my laptop. I of course googled the subject and found numerous other PDF manipulation applications but all of them were immediately rejected as a result of very suspect websites. In addition many of these applications included a hefty price tag which I really wanted to avoid. Finally I decided to try pdftk from PDFLabs via the MacPorts. Unfortunately to do this you need to be ready to jump into the command line vie the Terminal app. I am going to assume that you are and we will skip directly to the good stuff.
The first step I was to combine all of the individual PDF scans into one document which I did using the following syntax:
> pdftk Receipts-1.pdf Receipts-2.pdf Receipts-3.pdf output Receipts.pdf compress
The above example joins all of the PDF files together into one file and compresses the output. Each source PDF document can contain anywhere from one to many pages and they are concatenated in the order listed on the command line. Since I have 30 plus files each with multiple pages I found it easiest to write a short shell script to handle this for me.
The next problem I had to tackle was how to get the size of the file down below 5MB. My document was 11.7MB which was more than twice the size allowed by the mail server. So taking a less than elegant approach I used the burst functionality to basically explode all of the pages form this new document into separate files again. I know this may sound counter intuitive but I had a reason for doing this which I shall explain after the command line example of the burst operation.
> pdftk Receipts.pdf burst output Receipts-pg%20.pdf
In this example I have now take the new expenses document and exploded each page out into it’s own file. I did this so that I could use the built-in Mac app Preview to view each page separately and attempt to re-save as a black & white PDF. By doing this I was able to reduce the size of a given page to 50KB from 800KB. The reason I did this on a page by page basis because some of the pages became illegible or even completely blank. The afforded me the option of using the new black & white page or keeping the original.
Now that I had all of my pages converted as appropriate I culled the good discarding the cruft and modified my combination script. The combination of these new PDFs was relatively simple and followed the first example.
> pdftk Receipts-pg01.pdf Receipts-pg02-bw.pdf Receipts-pg03.pdf output Expenses.pdf compress
When I had finished I had a single PDF containing all of my receipts that was 4.5MB. Actually I got quite lucky with the sizing of this document as it turned out to be blind luck that i achieved this size. All that was left form me to do was to complete the Expense report documenting each transaction as well as convert foreign currencies to USD which I also noted on the actual receipt using Previews’ annotation tool. I even included the line item number from the expense report spreadsheet on the receipt just to help the bean counters follow along. Yes I am shall we say thorough.
All that aside I do understand that the command line is a rather scary place for most users. I decided to write the article to demonstrate how useful it can be and that it is not so scary of a place after all. Another reason I decided to write this is to demonstrate how easy it is to find and build useful applications from open source tools. There are thousands of applications available if you are willing to learn a few commands. If your Mac does not have the MacPorts installed they have a nice how to on their site that will walk you through the process.
I hope that you have enjoyed this short walk through the command line and thirty thousand foot view of the MacPorts. It is really a great system derived from the FreeBSD ports which is where the most of the UNIX core of Mac OS X came form in the first place.
ABOUT THE AUTHOR: Mikel King has been a leader in the Information Technology Services field for over 20 years. He is currently the CEO of Olivent Technologies, a professional creative services partnership in NY. Additionally he is currently serving as the Secretary of the BSD Certification group as well as a Senior Editor for the BSD News Network.
google says
I liked your article is an interesting technology
thanks to google I found you