Bingo!

Matts on 2002-05-19T16:26:15

PDFLib rocks. I hate to kinda self-gloat, but it's just a really nice module, very easy to use, and great for knocking together quick PDF's.

My wife is an english teacher. She has invented a game for a lesson this week called "Dictionary Bingo", where she reads out the meaning for a word, and you have to check it off on your bingo card. So I wrote a utility to generate the cards for her:

#!/usr/bin/perl -w
use strict;
use PDFLib;

my @words = ; chomp @words;

warn("got @words\n");

my $cards = shift @ARGV || die "Must supply number of cards\n";

print "Making $cards bingo cards\n";

my $pdf = PDFLib->new( filename => "bingo.pdf", papersize => "a4", creator => "Matt Sergeant", author => "Heather Sergeant", title => "Bingo!", );

foreach my $i (1..$cards) { my %seen;

print "Card $i\n"; $pdf->start_page; $pdf->set_font(face => "Helvetica", size => 30, bold => 1);

$pdf->print_boxed("Bingo!", mode => "center", x => 0, y => 740, w => 595, h => 50); $pdf->rect(x => 100, y => 200, w => 400, h => 400); $pdf->stroke;

$pdf->set_font(face => "Helvetica", size => 20, bold => 0);

for my $x (1..4) { for my $y (1..4) { my $word; while (1) { my $index = rand(@words); $word = $words[$index]; if (!$seen{$word}) { $seen{$word}++; last; } } $pdf->print_boxed($word, mode => "center", x => (100 + (($x - 1) * 100)), y => (160 + (($y - 1) * 100)), w => 100, h => 100); if ($y != 1) { $pdf->move_to( 100, (200 + (($y - 1) * 100)) ); $pdf->line_to( 500, (200 + (($y - 1) * 100)) ); $pdf->stroke; } } if ($x != 1) { $pdf->move_to( (100 + (($x - 1) * 100)), 200 ); $pdf->line_to( (100 + (($x - 1) * 100)), 600 ); $pdf->stroke; } } }

$pdf->finish;

1;


I'm skipping the __DATA__ section because I don't have it yet, but it basically contains all the words.