Showing posts with label book. Show all posts
Showing posts with label book. Show all posts

Wednesday, May 6, 2009

making books from a pdf

I needed to produce a book - or booklet more like from a PDF file I created. I wanted to print it on a duplex printer and fold the pages together (a signature). This is a common way of producing books.

I used pdftk (apt-get install pdftk) and pdfnup (apt-get install pdfjam).

The first thing to do was split my file into individual pages using:
 pdftk ./book.pdf burst

which produced a file for each page named 'pg_dddd.pdf' where d = digit.
Assuming my book has a page number which is a multiple of 4 (56 in the case below), I used the following script to concatenate these pages together in the correct order:

NOTE: This code will over write the file 'booksig.pdf' with a file of reorganised pages.

#!/usr/bin/perl -w

use strict;

my $totalPages = 56;

my $processedPages = 0;

my $pageOrderStr = "";
while ($processedPages < $totalPages/2) { $pageOrderStr .= sprintf ("pg_%04d.pdf pg_%04d.pdf pg_%04d.pdf pg_%04d.pdf ", $totalPages - $processedPages, $processedPages + 1, $processedPages + 2, $totalPages - $processedPages - 1); $processedPages += 2; } my $catCMD = "pdftk $pageOrderStr cat output booksig.pdf"; print `$catCMD`;

this resulted in a pdf call 'booksig.pdf'.
The final step was to use pdfnup to write these pages back to back:
pdfnup --nup 2x1 booksig.pdf

Which produced a file 'booksig-2x1.pdf' which I sent to my duplex printer and then bound together.

To it printed correctly, I chose 'Flip on Short Edge' two-sided printing. Which is non-standard. Apparently.

UPDATE: Julian spotted an error which is now fixed.

Thursday, August 7, 2008

config files

I'm using a config file as I work through the tutorial. This is an obvious thing to do and I completely agree with it. However, when I introduce this structure, I don't really want it to 'over-ride' existing values - I want to delete all the values which are now to be stored only in the config file.

I had to play around a bit. My model previously contained database connection information. When I introduce the config file, the values were taken from the file. However, when I deleted all of the relevant section from the Model, it broke the app. I needed to leave in a minimal stub:

__PACKAGE__->config(
schema_class => 'AddressBook::Schema::AddressDB');

Friday, August 1, 2008

day two, hurdle navigated

Well this is my second day working through the JROCK Catalyst book.

It has been a little frustrating - but this has reinforced some of the paradigms behind MVC and Catalyst so it can be thought of as useful.

Todays TIP: find_or_new does not return and empty model if it fails. The new it returns has the primary key which it failed to find. This could be 'undef' or 'null', and this object is not suitable for a subsequent: update_or_insert. Instead, do a find, if that fails, create a new object.

Thursday, July 31, 2008

Catalyst, day one

I've previously played with Ruby on Rails. My experience was ok with that. However, I considered 'no composite keys' a limitation.

So I've been watching the mailing lists of both CakePHP and Catalyst. I couldn't convince myself that CakePHP would allow for composite keys. In order to evaluate Catalyst, I have bought the book by Jonathan Rockaway and am working thought that.

This is the end of the first day at that and I thought note a couple my initial impressions.

On the book: It is worth visiting the errata. I went thought this and pencilled it into the book before I started reading.

On Catalyst: It seems a little complicated for my tastes. I'm expect that 'complicated' will become 'powerful' as I gain experience in it. We will see.

TIP for today: when creating a model in catalyst, and using a database with a user and password, you'll need to use something like: ...create=static dbi:Pg:dbname=testdatabase testuser testpassword if you want to include a username and password.