Binary Static

Interleaving two PDF files…

Posted in Applications, Hacking, Linux by Chris on October 17, 2010

Lightbulb…with no scripting required.  You’ll need the pdftk package though.  Say you’ve got a PDF file that has a two-sided layout and you want to trim the pages.  You could do this with pdfnup — however, your file may cut off from the even pages what it adds to the odd ones.  What now?  The solution is simple:

1. Use pdftk to split the file in even and odd pages seperately:

pdftk in.pdf cat 1-endeven output out.even.pdf
pdftk in.pdf cat 1-endodd output out.odd.pdf

2. Now would be the time to apply some pdfnup trimming magic to the two new files.

3. Use pdftk to burst these two files into single pages:

pdftk out.odd.pdf burst output %04d_A.pdf
pdftk out.even.pdf burst output %04d_B.pdf

4. Use pdftk to merge the pages back into one file, e.g.:

pdftk *.pdf cat output out.pdf

The important point here lies in step 3 when appending A or B to the odd and even page file names, because this allows glob sorting the pages like 0001_A.pdf 0001_B.pdf 0002_A.pdf 0002_B.pdf and so on.  I can’t believe I started to write a script before I realized how to solve this the simple way…

Tagged with: , , ,

How to Convert Git Log to ChangeLog

Posted in Coding, Linux by Chris on February 18, 2010

Git Logo

This is quite a useless endeavor, of course.  Since every fork from Git contains the whole change history, GNU-style ChangeLogs are pretty obsolete.  However, if you want to distribute your source files in a traditional tarball, you might want to add a ChangeLog file – and you might want it to look like the ones in the GNU coding standard.  This is where my shell script comes in, which I wrote yesterday while doing some serious procrastination:


#!/bin/sh
# Convert git log to GNU-style ChangeLog file.
# (C) Chris
if test -d ".git"; then
    git log --date-order --date=short | \
    sed -e '/^commit.*$/d' | \
    awk '/^Author/ {sub(/\\$/,""); getline t; print $0 t; next}; 1' | \
    sed -e 's/^Author: //g' | \
    sed -e 's/>Date:   \([0-9]*-[0-9]*-[0-9]*\)/>\t\1/g' | \
    sed -e 's/^\(.*\) \(\)\t\(.*\)/\3    \1    \2/g' > ChangeLog
    exit 0
else
    echo "No git repository present."
    exit 1
fi

This code goes conveniently in a Makefile template for Autotools, so you can create the ChangeLog on the fly, include it in the distribution tarball and have it unlinked afterwards. Again, there’s no need to have a ChangeLog lie around with Git.

Tagged with: , , , ,