Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Matts (1087)

Matts
  (email not shown publicly)

I work for MessageLabs [messagelabs.com] in Toronto, ON, Canada. I write spam filters, MTA software, high performance network software, string matching algorithms, and other cool stuff mostly in Perl and C.

Journal of Matts (1087)

Sunday May 19, 2002
11:26 AM

Bingo!

[ #5076 ]

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 = <DATA>;
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.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.