Skip to content

PDF Preview signatures internals

Mac OS X Lion introduced an interesting way to handle signatures on PDFs. If you open the app in Applications > Preview and go to Preview > Preferences > Signatures, you can sign on a paper and show it to the camera. Then, you can use it easily on any PDF file in Tools > Annotate > Signature. Easy!

You may notice that you can’t use any image in your system and you can’t send that same signature to other computer, and it will be lost if you do a clean (re)install of the OS. At least, Apple does not help you with that.

Using the great tool fseventer I found out where the signatures are stored!

$HOME/Library/Containers/com.apple.Preview/Data/Library/Preferences/com.apple.Preview.signatures.plist

If you are new to bash, $HOME is just a placeholder for /Users/<username>.
That PLIST file is just an array of images, each one with a signature.

So the next time you wonder where did your signatures went, you can restore that file from your backup.

Using an arbitrary image as a signature is still a work-to-do. My first guess is to binarize the data and load it as an NSImage/CGImage/… and hope not to crash. Anyway I don’t think I will ever need to do that now that I have my signature secured, but it could be useful for someone with some signatures scanned and processed.

Stallman Facts

These and many more at StallmanFacts.com.

 

Stallman can determine whether an arbitrary program will terminate.

Richard Stallman’s left and right hands are named “(” and “)”.

Richard Stallman never showers: he runs ‘make clean’.

Richard Stallman will revert the big rip by adding parenthesis to the dark matter.

Richard Stallman wrote a program so powerful, it knows the question to 42.

Richard Stallman wrote the compiler God used. The Big Bang was the Universe’s first segfault.

Richard Stallman first words were actually syscalls.

RMS doesn’t maintain code, he stares at it until it fixes itself out of reverence.

When Richard Stallman uses floats, there are no rounding errors.

Richard Stallman does not sleep. He yields.

Richard Stallman went out of scope for a while. Garbage Collector never dared to touch him.

Richard Stallman proved P=NP, twice!

When Richard Stallman counted his fingers as a kid, he always started with 0.

Richard Stallman don’t cut his hair because there is no GNU/Scissors.

Richard Stallman compiled the first version of gcc with an hexadecimal editor.

Compiling for OpenSceneGraph in Mac

In my previous post I showed how to install OSG 2.8.2 in Mac. Now I want to explain just a couple basic issues to compile a simple program.

In OpenSceneGraph there is not a one-for-all big header you have to include when you want something from OSG. Your headers will have a bunch of inclusions instead. ¿Is this bad? Well… you have to write a few more lines just one time, but the compilation will be much faster, saving you many precious minutes or hours of your life.

One thing you have to take into account is that OSG is still not ready for 64 bits in Mac for several reasons, so keep it i386 for now.

Finally, here is how to make it work for CMake and Xcode. You can download this toy material and play around:

my_osgplanets.zip

CMake

Some advise if you compile for CMake:

  1. Set the variable CMAKE_OSX_ARCHITECTURES to i386.
  2. You have to include both OpenThreads and OpenSceneGraph with the packages needed.

That is:
set(CMAKE_OSX_ARCHITECTURES i386)
FIND_PACKAGE(OpenThreads REQUIRED)
FIND_PACKAGE(OpenSceneGraph REQUIRED osgGA osgUtil osgDB osgViewer)

To compile using CMake (assuming you have it installed, of course):

cd /to/your/project/
mkdir build_cmake #or any other name
cd build_cmake
cmake ..
make
./osgplanets

As you can see, it is quite easy and extremely clean because everything is under your build directory, which can be anywhere.

Xcode

The equivalent for Xcode is to set i386 in the overview panel, and include the OpenThreads and osg frameworks, as well as any other framework for extra OSG modules.

You have a small example to play with, using the code taken from the osgplanets example from the OSG source code. There are compilation methods for CMake and an original Xcode project.

To compile with Xcode, just press the Build button. If you Build & Go, you will probably notice that there are no textures. That is because Xcode executes it without the variable OSG_FILE_PATH you should have in your .bash_profile. If you run the executable from the terminal, or double click the icon, it will work 😉

This should be the result.

osgplanets.png

Restore Google Scholar auto-import on BibDesk

Finally my headaches ended with web auto-import not working on BibDesk.

You just need to open Google Scholar on Bibdesk and go to Scholar Preferences (in the top right). There you just need to activate the radio button Show links to import citations into BibTex under Bibliography Manager section and save.

You can breathe again 😉

Now I just need to figure out how to do the same for IEEE, ACM, SpringerLink… because none is working!

Installing OpenSceneGraph 2.8.2 in Mac

I was surprised that the latest stable version of OpenSceneGraph (that is 2.8.3 at the time) didn’t come with a precompiled version for Mac.

After waisting too much time trying to compile OSG 2.8.3 using MacPorts and the source code via CMake and Xcode all of them unsuccessfully, I decided to use the previous version, which can be found precompiled in a nice package in the ARToolworks website (note it is compiled for 32 bits only).

When installing the package, what it calls Applications, refers to osgviewer, osgconv, osgversion and osgarchive, installed under /usr/local/bin.
Something you don’t need to install are the Bundles, because they are the same as Applications, just in a bundle.app way.

Once installed you’re done. You can now open a terminal and write osgversion.

If you are new to OSG, you might also be interested in the following.

You can find the examples under /Applications/OpenSceneGraph/Examples, and if you go there, you will se bundle applications instead of executable files, which I prefer in this case. To get a cleaner installation of these, I suggest to move the executables next to the plugins:

cd /Library/Application\ Support/OpenSceneGraph
sudo mkdir Examples
sudo cp /Applications/OpenSceneGraph/Examples/*.app/Contents/MacOS/* Examples
sudo rm -r /Applications/OpenSceneGraph

Now, for the final touch, download the OpenSceneGraph-Data, and copy it to /Library/Application Support/OpenSceneGraph/Data. And something you will like if you want to develop using OSG and try the example code are these few lines that you should add to your .bash_profile:

export OSG_FILE_PATH=/Library/Application\ Support/OpenSceneGraph/Data
export OSG_EXAMPLES_PATH=/Library/Application\ Support/OpenSceneGraph/Examples
export PATH=$OSG_EXAMPLES_PATH:$PATH

Now you can access all OSG examples, and having the environment variable OSG_FILE_PATH, OSG knows where to look for demo files and textures. For example, run: osgviewer cow.osg or the example osgplanets.

Have fun with OSG 🙂

Update: you can continue reading how to compile a simple OSG program in Mac.

Spanish voices for Festival

Recently I’ve had to install Spanish voices for Festival. I had heard that Festival ships with built-in Spanish voices, but that’s just not true. The most famous Spanish voice, called “el_diphone“, has only a commercial license, so it’s free but It’s not there by default.

Festival  is a complex synthesizer -it’s really the problem what is complex; Festival is easy to use for being a TTS- and can be a bit overwhelming at the beginning. Anyway, I’m just going to explain how to install Spanish voices.

The procedure for installing voices is really simple. There is a voices directory, usually /usr/share/festival/voices, that contains a subdirectory per language, and under there, a voice directory per language. That simple :).

Exempli gratia:
/usr/share/festival/voices
|-- english
| |-- kal_diphone
| `-- rab_diphone
|-- spanish
| |-- JuntaDeAndalucia_es_pa_diphone
| |-- JuntaDeAndalucia_es_sf_diphone
| `-- el_diphone
`-- us
|-- cmu_us_awb_cg
|-- cmu_us_rms_cg
`-- cmu_us_slt_arctic_hts

Next, I will show you how to get those two voices that you can see en the example above: el_diphone and JAndalucia_Indisys_MP_es_sf_diphone.

el_diphone

This is the “default” Spanish voice for Festival. If you search in google it’s not very difficult to find that if you use a Debian-like Linux, you can get it using apt-get or aptitude: aptitude install festvox-ellpc11k

But, what for the rest of us? There are some releases in compressed file. The module is called “festvox_ellpc11k”, so you can just search in google “festvox_ellpc11k.tar.gz”. I found a useful list of mirrors.

Just uncompress the file and move the directory to it’s right place (see above).

Junta de Andalucía voices

The “Junta de Andalucía” released a couple of voices “Pedro” and “Silvia” in 2007. The forge (update) of the project contains the files we need, and it claims to have documentation, but it’s completely useless. You just need to download the last deb packages for Pedro and Silvia.

If you use a Debian-like OS, you just have to install the packages. If you use another OS, don’t worry 😉 It’s easy to get the files: You just need to decompress the file  typing this in the terminal for each .deb file:

ar vx festvox-palpc16k_1.0-1_all.deb
tar -xzvf data.tar.gz

Then move the directory ./usr/share/festival/voices/spanish/JuntaDeAndalucia_es_pa_diphone to it’s right place, and repeat the procedure for the other .deb file.

Testing the voices

If you don’t know how to try the voices, this is a quick tutorial. This is a terminal capture:

$festival

Festival Speech Synthesis System 2.0.95:beta April 2010
Copyright (C) University of Edinburgh, 1996-2010. All rights reserved.
(...)
festival> (voice_el_diphone)
festival> (SayText "Hola, esto es una prueba de la voz en español")
festival> (voice_JuntaDeAndalucia_es_pa_diphone)
festival> (SayText "Hola, esto es una prueba de la voz de Pedro")
festival> (voice_JuntaDeAndalucia_es_sf_diphone)
festival> (SayText "Hola, esto es una prueba de la voz de Silvia")

I think it’s not necessary to explain that simple code 😉 The quality of the voices is not the best I’ve ever heard, but it’s not too bad. What I specially dislike is that none of the voices can say certain words, and they just spell them.

I hope this helps anyone. Peace.

Update

It seems the the web for downloading the voices is no longer in active. Fortunately I have a local copy of the voices. You can download them here:

Please, note that the files have the extension .jpg. You have to rename them to .deb, and extract them as showed previously. This is because WordPress does not allow to upload that extension and we need to do this little hack.

How to edit PDF metadata (Mac/Linux/Windows)

Metadata is a piece of information that is not part of the main content of the data, such as image and PDF files, but that is attached to it giving you some useful information such as the author, program used to create it, date of creation/modification, GPS location in case of photographs, and any other interesting info.

It is very common that programs that let you save or export in PDF format does not allow to customize metadata, and sometimes you want to add this kind of information for many reasons. In this post you will see

Introduction to PDF metadata

PDF files are part binary, part plain text. In fact you can open a PDF file with a plain text editor (such as TextMate or vi) and you will understand some things, although everything may seem quite messy at first sight. By the end of the file you might see some lines like these if the file has metadata embedded:

<<
/Author ( ... )
/Creator ( ... )
/Producer ( ... )
>>

You could simply change those lines as desired and you’d be done. However I do not recommend doing that because if you change the file size and you don’t update that explicit value at the very endof the file, it would be corrupted (it’s not a catastrophic corruption and you’d still be able to open the file, but it’s a corruption anyway).

There is the good way to do that: using pdftk.

Installing pdftk

The open source project pdftk is a command line tool for general PDF edition: rotate, merge, split, edit metadata…

Linux users can install it using any package manager such as apt-get. There are also debian packages in the pdftk website.

Windows users may follow the instructions in the pdftk page to download the executable.

Mac users have two ways:

  • If you know and like MacPorts, you should try there first, although I had some troubles with a dependency and didn’t work.
  • In the blog fredericiana you can find a dmg installer containing a precompiled distribution of pdftk with all libraries needed. It worked perfectly for me.

If you use Mac you are lucky, because there is also an independent free project called PDF MetaEdit (I don’t know German either, but the “download” button is very helpful ;)), which is just a helpful front-end for pdftk (In case you prefer a direct link…). I don’t know any other similar program for Linux, sorry.

PDF MetaEdit is ready to work with a MacPorts distribution and it looks for pdftk executable in the path “/opt/local/bin/pdftk”, and I could not find a way to change that path (it seems to be miserably hard-coded). I suggest to create a soft link to that path from the terminal:

sudo mkdir -p /opt/local/bin/
sudo ln -s /usr/local/bin/pdftk /opt/local/bin/pdftk

Now PDF MetaEdit should work properly and you should be able to drag&drop any pdf file to the window and change its metadata.

Command line utility for pdftk

One always should be able to take the most of any functionality of any program using the command line (that’s why I am reluctant to build only graphical interfaces without command line interface).

To change the metadata of a file you have first to get the intermediate metadata file, modify it (or create a new one or a template you have) and then embed it to the file. The next command shows the metadata of a PDF file:

$ pdftk file.pdf dump_data
InfoKey: Title
InfoValue: Title of the document
InfoKey: Author
InfoValue: Name of the author
InfoKey: Creator
InfoValue: cairo 1.8.8 (http://cairographics.org)
InfoKey: Producer
InfoValue: cairo 1.8.8 (http://cairographics.org)
NumberOfPages: 1

You have to copy this in a file and add any other key or modify it. To save it into a file you can try the command ‘pdftk file.pdf dump_data output metadata.txt‘, but I’m having segmentation faults. A redirection of the standard output to a file will do the job: ‘pdftk file.pdf dump_data > metadata.txt‘ (only for Linux/Mac).

Basically you can do the next actions to change metadata:

  • Add a new key: Include the key and the value. I beliebe that keys should not contain spaces.
  • Modify the value of a key: just change its value.
  • Delete a key: leave the key and set the value to blank.

You must have in mind that if you do not include an existing key along with its value into your metadata.txt, that key will not be changer nor removed from the PDF file.

If you want to include accents, tildes or any odd character, you have to write the HTML format. Make sure you write the number notation instead of the entity (e.g. & for ampersand, instead of &amp;).

Once you have your new metadata, you have to know that pdftk will take both the original PDF file and the modified metadata file to create a new PDF with the desired result. Of course, you should check that you can see the new PDF file just like the original before you delete it. This is the command:

pdftk file.pdf update_info metadata.txt output newfile.pdf

That’s all folks 🙂


In my case I have created a bunch of files with Inkscape, and I will create many more for a long time. Here is a small shell script for Linux/Mac that can be helpful to automatize this process (beware that I don’t backup any PDF because originals in SVG are not touched at all in this script). I will always use the same metadata, so I have the next file: ~/.pdfmetadata:

InfoKey: Creator
InfoValue:
InfoKey: Producer
InfoValue:
InfoKey: Author
InfoValue: Santiago González

And the script is:

#!/usr/bin/env bash
# This script assumes all inputs are PDF files and tries to embed
# the metafile data inf ~/.pdfmetadata

for i in $*; do
mv $i _$i
pdftk _$i update_info ~/.pdfmetadata output $i
rm _$i
done

I hope this helps anyone.

Enjoy.

LaTeX Makefile

This is a Makefile ready for LaTeX projects. It has the next features:

  • Recompiles only when needed (e.g. undefined references or citations)
  • Support for bibtex
  • Support for meta graphics using metafun
  • Recursive Makefile
  • Recursive clean and distclean
  • clean: removes auxiliary files
  • distclean: removes auxiliare files and the final pdf (not other pdfs).

Download

  • From my GitHub project
  • Using Git: git clone git://github.com/sangonz/latex_makefile.git