http://qs321.pair.com?node_id=414845
Category: Win32 Stuff
Author/Contact Info Thomas Stanley
Description: After seeing brian_d_foy describe how he used PDF::Create and PDF::Labels to create some mailing labels, I decided to expand on his code a little bit, and wrap it in a Tk based gui.
#!perl -w
use strict;
use Tk;
use Tk::Dialog;
use PDF::Create;
use PDF::Labels;

my %Address_List; 
my $cntr=0;
my $VERSION='0.01';

my $Main=new MainWindow;
my $MenuFrame=$Main->Frame(-relief=>'flat',-borderwidth=>2);
$MenuFrame->grid;
$MenuFrame->Menubutton(-text=>'File',-menuitems=>[['command'=>'Exit',-
+command=>\&Exit]])->pack(-side=>'left');
$MenuFrame->Menubutton(-text=>'Help',-menuitems=>[['command'=>'About',
+-command=>\&About]])->pack(-side=>'right');

my $lblpos=$Main->Label(-text=>'Default Label Position:');
my $pos=$Main->Entry(-width=>2);
$lblpos->grid($pos,-sticky=>'w');
$pos->focus;

my $un=$Main->Label(-text=>'Name:');
my $name=$Main->Entry(-width=>40);
$un->grid($name);

my $Addr=$Main->Label(-text=>'Street:');
my $str=$Main->Entry(-width=>40);
$Addr->grid($str);

my $CSZ=$Main->Label(-text=>'City, State Zip-Code');
my $csz=$Main->Entry(-width=>40);
$CSZ->grid($csz);

my $AddBtn=$Main->Button(-text=>'Add',-command=>sub{Add_List($name,$st
+r,$csz)});
my $CrtBtn=$Main->Button(-text=>'Create PDF',-command=>sub{Create_PDF(
+$pos)});
my $ExtBtn=$Main->Button(-text=>'Exit',-command=>sub{ Exit()});
$AddBtn->grid($CrtBtn,$ExtBtn);

MainLoop;

sub Add_List{
  my($Name,$Str,$Csz)=@_;
  my $N=$Name->get;
  my $S=$Str->get;
  my $C=$Csz->get;
  $cntr++;
  $Address_List{$cntr}=[$N,$S,$C];
  &Clear;
}

sub Create_PDF{
  my $position=shift;
  my $p=$position->get;
  if($p eq ""){ $p = 0; }  
  my $pdf = new PDF::Labels(
                        $PDF::Labels::PageFormats[0],
                                filename=>'Labels.pdf',
                                Author=>'PDF_Label_Maker',
                                Title=>'Labels'
                );
  $pdf->setlabel($p);      
  foreach my $key(keys %Address_List){
    $pdf->label("$Address_List{$key}[0]",
            "$Address_List{$key}[1]",
            "$Address_List{$key}[2]");
  }
  $pdf->close();
  &Done; 
}

sub Clear{
  $pos->delete(0,'end');
  $name->delete(0,'end');
  $str->delete(0,'end');
  $csz->delete(0,'end');
  $pos->focus;
}

sub About{
  my $about=$Main->Dialog(-title=>'About PDF Label Maker',-text=>"PDF 
+Label Maker Version $VERSION\n  Written by Thomas Stanley",-default_b
+utton=>'Ok');
  $about->Show;
}

sub Exit{
    exit 0;
}

sub Done{
  my $Done=$Main->Dialog(-title=>'File Created',-text=>"Labels.pdf was
+ created",-default_button=>'Ok');
  $Done->Show;
}
Replies are listed 'Best First'.
Re: PDFLM
by zentara (Archbishop) on Dec 15, 2004 at 09:52 UTC
    From first appearances, it would seem that this would run on linux too, but I get an error
    Tk::Error: Can't locate object method "setlabel" via package "PDF::Lab +els::Producer" at ./pdf-labels-tk.pl line 62.
    So I'm guessing the PDF::Labels module from ActiveState has a few more features than the one from cpan?

    I'm not really a human, but I play one on earth. flash japh