vendredi 13 juillet 2007

Mac OS X converting A4 to US letter (or vice versa) when saving PDF file

Today I had to generate a PDF version of a Word document. Fortunately enough, Mac OS X has great integration with PDF documents, so it's possible to export a PDF document directly from the "Print" dialog of any application.

There was a little problem, however - the source Word document came in "US Letter" format and the PDF document had to remain in the same format. It turned out that the "Save as PDF" action converted the page to the local A4 format. After searching a little bit on the net I found some solutions (like this one) which seemed a little too complicated for such a simple thing.

I was thinking that I should try opening the document in OpenOffice to export it directly from there, but I decided to try out some of the options in the System Preferences before jumping in the hell of fixing the layout.

I tried switching to "American" measurement units (found under System Preferences -> International -> Formats) and it worked! After exporting the document in the correct "US Letter" format I switched back to "Metric" system and the system started generating PDFs in the plain old A4 format. Youpee!

That's it for now - I hope that you found it useful!

C ya!
Alex


PS. I'm using Mac OS X 10.4.10, so this procedure may not work in the older releases

mercredi 20 juin 2007

Counting the number of files in all subdirectories with a one-line Bash script

As I usually forget the scripts I'm using from time to time, I decided to backup them to a place where they'll be easily accessible and could eventually be used by someone needing the same thing.

Enough talking already. This time I needed to find the number of PDF files in all my directories (listed directory by directory). Currently I'm working under Linux, so a one-line bash script seemed the ideal solution. Here's what I came up with:

for x in `ls -d */ . | tr ' ' '*' ` ; do x=`echo "$x" | tr '*' ' '` ; find "$x" | grep -i "\.pdf$" | wc -l | xargs -i/// echo /// files in $x ; done



Here is a sample output of the execution:
1069 files in .
4 files in App Help/
1 files in Books/
73 files in Lectures/
12 files in Personal/
979 files in Work/


Some explanations:
ls -d */ - lists all subdirectories of your current directory. If you want to list all hidden directories add ".*/" (as found in the comments of this post).

tr ' ' '*' - replaces all spaces with * so that the "for" loop does not break directory names containing spaces. The name is restored with another "tr". I used the symbol * as it is very rare that someone would put it in the name of a directory, but who knows.

find "$x" - outputs all files of the given subdirectory to the standard output, which in this case is:

grep -i "\.pdf$" - which filters out only the files ending with .pdf (case insensitive).

wc -l - counts the number of lines (ie. the number of files) and the output is passed to xargs, which is used to format the output.

xargs -i/// echo /// files in $x - the "-i" option specifies the string that will be replaced with the text read from the standard input (ie. the number of files). I'm using a string that is impossible to put in a filename, so that we have a nicely formatted output.


Ok, that's it for now. I hope that someone might find this one useful.

Alex

mardi 15 mai 2007

Hi everyone !

Hello everyone !
Here I join the blogging madness.. only time will show if everything's going to be ok ;)