Added support for different page formats (A4, letter, custom) and cleaned up/fixed code.

Solves issue #5.

See commit messages.