Monday, February 29, 2016

Editing PDF with a Text Editor (Emacs)

I'm again making a new edition of Book of Vaadin. The PDF was made some time last year and the place in which it will be printed has changed.

In earlier times, this kind of changes to editions would be a matter of the printing house and little interest to the authors. One interesting example is the printer's key, which was a list of numbers to indicate the print run. The printer (a person) simply had to file off the letters from the Linotype plates. Changing the print location was not possible in Linotype or offset, but easy in even earlier letterpress printing. But here we are, in the age of technology, that the people doing printing do not want to open a PDF editor to change such details.

There are some PDF editors for Linux, but I want to be careful about not changing the content in any other way. Thereby, editing PDF with a text editor is handy for such tasks. The problem is that PDF is compressed, so you can't edit it directly.

The very simple solution that I used was to use the pdftk tool to uncompress the file, edit it with XEmacs, and then compress it again.

$ pdftk original.pdf output uncompressed.pdf uncompress

Then edit it in Emacs (which is suitable for editing even huge binary files) and compress again:

$ pdftk uncompressed.pdf output edited.pdf compress

Start heating the printing machines!

No comments: