Just Beyond The Bridge

How To Compress PDFs As You Create Them On A Mac

Tuesday, April 21, 2009

Pigeon-holed in “Technology

If you’ve ever created a PDF using OSX you’ll know that it’s very simple. Macs come with out-of-the-box PDF support which means you don’t need a program like Adobe Acrobat Reader (or anything more heavyweight) to open or save your files as such.

However, you’ll also know that emailing the files it creates takes much longer than it should - the created files are massive in relative terms.

I’ve created one-page invoices using PDFs for a long time, and thankfully, due to this great little PDF compression plugin, they are crunched down to a sensible size from the outset. However, I recently switched to let Billings handle my invoicing and it uses the default OSX PDF creation tool to generate it’s PDFs - big files ahoy.

To give you an idea of the difference in file size between a compressed one page document - Billings chucks out a 1.4Mb file, whereas my compressed versions of the same documents are about 19Kb. Not ideal when you quickly want to output an invoice, attach and send it.

So how do you solve it? Well there are some nifty features in OSX that you may not be aware of (or at least not use), namely Folder Actions. Essentially folder actions allow you to run a script every time a file is placed in or removed from a folder on your Mac.

This creates a great little hook on which we can run a script to compress the files in a specific directory then move them to a ‘Compressed’ folder once done.

Step-by-Step: How to Do It

1. Download and Install Compression Plugin

Download and install the PDF compression plugin. It’s a Quartz filter workflow that uses well-chosen settings to reduce your file size down. You will also now benefit from the use of it everytime you encounter a save dialogue from now on.

2. Create an Automator Workflow

Automator is a free program bundled in every OS X Mac (have a look in your Applications folder). It allows you to run series of tasks automatically in a single process. You simply need to create a workflow consisting of:

  1. Get Specified Finder Items (once added to the workflow, click Add to select the directory which will contain files to be compressed.
  2. Get Folder Contents
  3. Apply Quartz Filter to PDF Documents (Select ‘Compress PDF’ from the drop-down - this will only appear if you have installed the plugin as above)
  4. Move Finder Items (change the location to a place where the final, compressed files will be automatically moved)

3. Test The Workflow

Place a test PDF in your ‘Compressor directory’ (specified in step 1 of the workflow) then run it. It should compress this PDF, then move it to the ‘Compressed directory’ you specified in step 4, leaving the ‘Compressor directory’ empty.

Once you’ve got that working, you can automate the process, so this executes every time a PDF is saved or moved into the folder. Click save, and Save as Application (as opposed to Save as Workflow, otherwise every time you run it, the Automator program will want to load up fully instead of run in the background).

4. Create A Script

You now need to create little AppleScript which can run this workflow application.

Go to /Libaray/Scripts/Folder Action Scripts/

Duplicate one of the existing scripts, and rename it to something sensible like PDF - compressor.script

Open it and paste the following. You must manually alter the path to your Automator application as appropriate.

The code below is wrapping because of my thin blog layout. Best idea is to copy and paste directly, or View Source of this page to determine where the line breaks actually are if you are not sure.


on adding folder items to this_folder after receiving added_items
try
tell me
do shell script “open -a /Users/Andy/Documents/My\\ Mac/Compress\\ PDFs.app”
end tell
end try
end adding folder items to

Note! All spaces in the path must be double backslashed as above. To test if your typing is correct, paste the bit between the quote marks (e.g. open -a /Users/Andy/Documents/My\\ Mac/Compress\\ PDFs.app) into Terminial and run. If it runs the Automator application you created, your script will work. If it doesn’t, check the path you have typed.

Save it and close the Script Editor.

5. Set It Up

Find your ‘Compressor directory’ (specified in step 1 of the workflow) and right-click on it. From the menu that appears, select More > Configure Folder Actions…

Tick the ‘Enable Folder Actions’ box, then press the Add icon (+) to add the ‘Compressor directory’ as a trigger folder. Select it, and make sure the ‘On’ tickbox it ticked.

Next, click the Add icon (+) for the right hand pane to add a script. You should be able to find and select the AppleScript you have just created (something like PDF - compressor.script).

6. Done!

Close the window and you’re done. Every time somebody pastes or saves into the ‘Compressor directory’, the folder action will kick in, launch the AppleScript and that in turn will execute the Automator compression tool and move the compressed version of the PDF into the ‘Compressed directory’. Sorted.

Of course, there is lots more scope with this. Automator means you don’t need to know much AppleScript to get this going, but you can really push the boundaries if you are willing to experiment. This setup suits me, but it’s likely you’ll need to experiment to get it to the way you need it.

Comments (2)

This is Just Beyond The Bridge

Something About Me

Called Andy, I am passionate about design, love to travel, and have a knack for all things digital. This is the full story…

March 2010
M T W T F S S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

More Stuff

Back Catalogue

  1. Jan ‘10
  2. Oct ‘09
  3. Sep ‘09
  4. Aug ‘09
  5. Jul ‘09
  6. Jun ‘09
  7. Apr ‘09
  8. Mar ‘09
  9. Feb ‘09
  10. Jan ‘09
  11. Dec ‘08
  12. Nov ‘08
  13. Oct ‘08
  14. Sep ‘08
  15. Aug ‘08
  16. Jul ‘08
  17. Jun ‘08
  18. May ‘08
  19. Apr ‘08
  20. Mar ‘08
  21. Feb ‘08
  22. Jan ‘08
  23. Dec ‘07
  24. Nov ‘07
  25. Oct ‘07
  26. Sep ‘07
  27. Aug ‘07
  28. Jul ‘07
  29. Jun ‘07
  30. May ‘07
  31. Apr ‘07
  32. Mar ‘07
  33. Feb ‘07
  34. Jan ‘07
  35. Dec ‘06
  36. Nov ‘06
  37. Oct ‘06
  38. Sep ‘06
  39. Aug ‘06
  40. Jul ‘06
  41. Jun ‘06
  42. May ‘06
  43. Apr ‘06
  44. Mar ‘06
  45. Feb ‘06
  46. Jan ‘06
  47. Dec ‘05
  48. Nov ‘05
  49. Oct ‘05
  50. Sep ‘05
  51. Aug ‘05
  52. Jul ‘05
  53. Jun ‘05
  54. May ‘05
  55. Apr ‘05
  56. All Archives

Search