For Programmers: Free Programming Magazines  


Home > Archive > PERL Modules > February 2005 > Problems using Module PDF::Create









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Problems using Module PDF::Create
kielhd

2005-02-18, 8:56 am

Hi NG,

I have problems using the above module.
After creating the first page ok with text and drawing.
I have Problems to put some text on the second page. I is ok to put
some lines on the secand page, but the text appears still on the first
page.

Any ideas?
Regards,
Henning

#!C:\Perl\bin\perl.exe

use MP3::Info qw(:all);
use PDF::Create;
use File::Find;
use bytes;
use Win32API::File 0.08 qw( :ALL );

get_parameter();

#
# Ermitteln des CD-Laufwerks ( $uDriveType = 5 )
#
get_cdlw();

#
# Ermitteln des CD-Labels
#
get_cd_label();

$filename = $volume . ".pdf";

my $pdf = new PDF::Create('filename' => $filename,
'Version' => 1.2,
'PageMode' => 'UseOutlines',
'Author' => 'Henning Deschka',
'Title' => 'Inhaltsverzeichniss von
MP3-CDs',
'Subject' => 'Auflistung der Titel auf
einer MP3-CD',
);
my $root = $pdf->new_page('MediaBox' => [ 0, 0, 792, 612 ]);

########################################
#######################################
# Prepare 1st page
########################################
#######################################

my $page = $root->new_page;
my $toc = $pdf->new_outline('Title' => "Inhalt von \>\> $volume \<\<",
'Destination' => $page);

# Variablen für das Cover
$breite = 372 * 2;
$hoehe = 600;

COVER();

########################################
#######################################
# Prepare 2nd page
########################################
#######################################

my $page2 = $root->new_page;
my $toc2 = $pdf->new_outline('Title' => "Rückseitiges Cover von \>\>
$volume \<\<",
'Destination' => $page2);

# Variablen für das Cover
$breite2 = 450;
$hoehe2 = 351;

COVER2();

########################################
#######################################

# Prepare 2 fonts
my $f1 = $pdf->font('Subtype' => 'Type1',
'Encoding' => 'WinAnsiEncoding',
'BaseFont' => 'Helvetica');
my $f2 = $pdf->font('Subtype' => 'Type1',
'Encoding' => 'WinAnsiEncoding',
'BaseFont' => 'Helvetica-Bold');

########################################
#######################################

$DUMMY=""; #
$NR_CD=0; # Nr. auf der CD
$NR_ARTIST=1; # Nr. der jeweiligen CD
init_time();

#
# Variablen für PDF-Erstellung
#
$SIZE = 6;
$COL = 10;
$LINEMAX = 57;
$LINE = 0;

$SIZE2 = 12;
$COL2 = 30;
$LINEMAX2 = 57;
$LINE2 = 30;


#
# Lesen der Dateien und füllen eines Arrays
#
find(\&wanted, $dir);
chomp(@dateien);

#
# Ausgabe der formatierten ID3-Tag-Informationen
#

foreach (@dateien)
{
add_time(); # Zeit jedes Albums ermitteln
$NR_CD +=1;
$NR_ARTIST +=1;
$info = get_mp3info($_);
$time = $info->{TIME};
$tag = get_mp3tag($_);
$title = $tag->{TITLE};
$artist = "$tag->{ARTIST}" if ( exists $tag->{ARTIST} );
$album = "$tag->{ALBUM}" if ( exists $tag->{ALBUM} );
$dummy=chop($title); # Irgendwie wird
$title = substr($title,0,38); # das letzte
$title .= $dummy; # Zeichen benötigt


#
# Zusammenstellen der richtigen Überschrift
#
if ( $artist ne "" && $album ne "" )
{
$HEADER=$artist." - ".$album;
}

if ( $artist ne "" && $album eq "" )
{
$HEADER=$artist;
}

if ( $artist eq "" && $album ne "" )
{
$HEADER=$album;
}

if ( $artist eq "" && $album eq "" )
{
$album = "Diverses";
$HEADER=$album;
}

#
# Prüfen, ob eine neue CD eingelesen wird
# Ausgabe der neuen Überschrift
#

if ( ($DUMMY ne $HEADER) && ($COL == 10) )
{
print_time() if ( $NR_CD != 1 );
$LINE += 2;
print_header();
$NR_ARTIST=1;
print_back();

}

if ( $LINE >= $LINEMAX && $COL == 10 )
{
get_line();
$COL = 10 + $breite / 4 * 1;
print_header();
}

if ( ($DUMMY ne $HEADER) && ($COL == 10 + $breite / 4 * 1) )
{
print_time() if ( $NR_CD != 1 );
$LINE += 2;
print_header();
$NR_ARTIST=1;
}

if ( $LINE >= $LINEMAX && $COL == 10 + $breite / 4 * 1 )
{
get_line();
$COL = 10 + $breite / 4 * 2;
print_header();
}

if ( ($DUMMY ne $HEADER) && ($COL == 10 + $breite / 4 * 2) )
{
print_time() if ( $NR_CD != 1 );
$LINE += 2;
print_header();
$NR_ARTIST=1;
}

if ( $LINE >= $LINEMAX && $COL == 10 + $breite / 4 * 2 )
{
get_line();
$COL = 10 + $breite / 4 * 3;
print_header();
}

if ( ($DUMMY ne $HEADER) && ($COL == 10 + $breite / 4 * 3) )
{
print_time() if ( $NR_CD != 1 );
$LINE += 2;
print_header();
$NR_ARTIST=1;
}

if ( $LINE >= $LINEMAX && $COL == 10 + $breite / 4 * 3 )
{
$LINE += 5;
$LINEMAX = 96;
$COL = 10;
print_header();
}

$OUT_1 = sprintf "%03d.\t%03d.\t%s", $NR_CD, $NR_ARTIST, $title;
$OUT_2 = sprintf "%-5s\n", $time;

#printf("%-60s%s", $OUT_1, $OUT_2);
#printf SCHREIBEN ("%-60s%s", $OUT_1, $OUT_2);
$LINE += 1;
$page->string($f1, $SIZE, $COL, 612 - 10 - $LINE * $SIZE, $OUT_1);
$page->string($f1, $SIZE, $COL + 150, 612 - 10 - $LINE * $SIZE,
$OUT_2);
}

add_time();
print_time() if ( $NR_CD != 1 );

$pdf->close;

#close(SCHREIBEN);

exit 0;

########################################
#######################################
# CD-Cover Zeichnen
########################################
#######################################

sub COVER
{

# Rahmen

$x1 = 0;
$y1 = 612 - 0;
$x2 = 0 + $breite;
$y2 = 612 - 0;
$page->line($x1, $y1, $x2, $y2);

$x1 = 0 + $breite;
$y1 = 612 - 0;
$x2 = 0 + $breite;
$y2 = 612 - 0 - $hoehe;
$page->line($x1, $y1, $x2, $y2);

$x1 = 0 + $breite;
$y1 = 612 - 0 - $hoehe;
$x2 = 0;
$y2 = 612 - 0 - $hoehe;
$page->line($x1, $y1, $x2, $y2);

$x1 = 0;
$y1 = 612 - 0 - $hoehe;
$x2 = 0;
$y2 = 612 - 0 ;
$page->line($x1, $y1, $x2, $y2);


$hoehe = 370;
$x1 = 0 + $breite;
$y1 = 612 - 0 - $hoehe;
$x2 = 0;
$y2 = 612 - 0 - $hoehe;
$page->line($x1, $y1, $x2, $y2);
$hoehe = 600;


# senkrechte Striche

$x1 = 0 + $breite / 4 * 1;
$y1 = 612;
$x2 = 0 + $breite / 4 * 1;
$y2 = 612 - $hoehe;
$page->line($x1, $y1, $x2, $y2);

$x1 = 0 + $breite / 4 * 2;
$y1 = 612;
$x2 = 0 + $breite / 4 * 2;
$y2 = 612 - $hoehe;
$page->line($x1, $y1, $x2, $y2);

$x1 = 0 + $breite / 4 * 3;
$y1 = 612;
$x2 = 0 + $breite / 4 * 3;
$y2 = 612 - $hoehe;
$page->line($x1, $y1, $x2, $y2);

}


sub COVER2
{

# Rahmen

$x1 = 0;
$y1 = 612 - 0;
$x2 = 0 + $breite2;
$y2 = 612 - 0;
$page2->line($x1, $y1, $x2, $y2);

$x1 = 0 + $breite2;
$y1 = 612 - 0;
$x2 = 0 + $breite2;
$y2 = 612 - 0 - $hoehe2;
$page2->line($x1, $y1, $x2, $y2);

$x1 = 0 + $breite2;
$y1 = 612 - 0 - $hoehe2;
$x2 = 0;
$y2 = 612 - 0 - $hoehe2;
$page2->line($x1, $y1, $x2, $y2);

$x1 = 0;
$y1 = 612 - 0 - $hoehe2;
$x2 = 0;
$y2 = 612 - 0;
$page2->line($x1, $y1, $x2, $y2);


# senkrechte Striche

$x1 = 18;
$y1 = 612;
$x2 = 18;
$y2 = 612 - $hoehe2;
$page2->line($x1, $y1, $x2, $y2);

$x1 = $breite2 - 18;
$y1 = 612;
$x2 = $breite2 - 18;
$y2 = 612 - $hoehe2;
$page2->line($x1, $y1, $x2, $y2);

}

# CD-Lesen

sub wanted
{
if ( $_ =~ /\.mp3$/ )
{
$File::Find::name =~ s/\//\\\\/g;
$File::Find::name =~ s/\:\//\:/;
push (@dateien, $File::Find::name);
}
}

sub get_line
{
if ( $LINEMAX == 57 )
{
$LINE = 2;
}
else
{
$LINE = 63;
}
}

sub add_time
{
my ($min, $sec)=0;
($min, $sec) = split(/:/,$time);

$ALBUM_MIN_GESAMT += $min;
$ALBUM_SEC_GESAMT += $sec;

if ( $ALBUM_SEC_GESAMT >= 60 )
{
$ALBUM_SEC_GESAMT -= 60;
$ALBUM_MIN_GESAMT += 1;
}

if ( $ALBUM_MIN_GESAMT >= 60 )
{
$ALBUM_MIN_GESAMT -= 60;
$ALBUM_HR_GESAMT += 1;
}
#print SCHREIBEN " \n$time $ALBUM_HR_GESAMT:$ALBUM_MIN_GESA
MT:$ALBUM_SEC_GESAMT\n";
}

sub format_time
{
### Stunden ###
if ( $ALBUM_HR_GESAMT == 0 )
{
$ALBUM_GESAMT .= " ";
}

if ( $ALBUM_HR_GESAMT > 0 && $ALBUM_HR_GESAMT < 10)
{
$ALBUM_GESAMT .= "0" . $ALBUM_HR_GESAMT . ":";
}

if ( $ALBUM_HR_GESAMT > 10)
{
$ALBUM_GESAMT .= $ALBUM_HR_GESAMT . ":";
}

### Minuten ###
if ( $ALBUM_MIN_GESAMT == 0 )
{
$ALBUM_GESAMT .= "00:";
}

if ( $ALBUM_MIN_GESAMT > 0 && $ALBUM_MIN_GESAMT < 10)
{
$ALBUM_GESAMT .= "0" . $ALBUM_MIN_GESAMT . ":";
}

if ( $ALBUM_MIN_GESAMT > 10)
{
$ALBUM_GESAMT .= $ALBUM_MIN_GESAMT . ":";
}

### Sekunden ###
if ( $ALBUM_SEC_GESAMT == 0 )
{
$ALBUM_GESAMT .= "00";
}

if ( $ALBUM_SEC_GESAMT > 0 && $ALBUM_SEC_GESAMT < 10)
{
$ALBUM_GESAMT .= "0" . $ALBUM_SEC_GESAMT;
}

if ( $ALBUM_SEC_GESAMT > 10)
{
$ALBUM_GESAMT .= $ALBUM_SEC_GESAMT;
}

#print "$ALBUM_GESAMT\n";
}

sub init_time # Spielzeit des Albums
{
$ALBUM_HR_GESAMT=0;
$ALBUM_MIN_GESAMT=0;
$ALBUM_SEC_GESAMT=0;
$ALBUM_GESAMT="";
}

sub print_time
{
format_time();
$LINE += 1;
$OUT_2 = sprintf "%8s\n", $ALBUM_GESAMT;
$page->string($f2, $SIZE, $COL + 141, 612 - 10 - $LINE * $SIZE,
$OUT_2);
# $LINE += 2;
init_time();
}

sub print_header
{
$OUT = sprintf "%s\n", $HEADER;
$page->string($f2, $SIZE, $COL, 612 - 10 - $LINE * $SIZE, $OUT);
$DUMMY=$HEADER;
}

sub get_parameter ### Aufrufparameter auslesen
{
if ( $ARGV[0] eq "-h" )
{
printf "
Dieses Programm erstellt ein Inhaltsverzeichniss für CD's
mit Dateien im MP3-Format.
Die ID3-Tags werden ausgelesen und daraus eine PDF-Datei generiert,
die als Cover für eine CD genutzt werden kann.
";
exit;
}

$dir = $ARGV[0];
$dir =~ tr/a-z/A-Z/;
#print "$dir\n";
}

sub get_cdlw
{
@roots= getLogicalDrives();
foreach $drive (@roots)
{
$uDriveType= GetDriveType( $drive );
#print "$drive\t$uDriveType\n";
if ( $uDriveType == 5 )
{
$dir = $drive;
chop($dir);
#print "Das CD-ROM befindet sich auf Laufwerk $dir\n";
break;
}
}
}

sub get_cd_label
{
open(CMD,"vol $dir |");
while (<CMD> )
{
if( /ist\s*(.*)/ )
{$volume= $1;}
}
close(CMD);
$dir .= "\\";
#$volume="Test";
#print "Label von Laufwerk $dir -> $volume\n";
}

sub print_back
{
$LINE2 += 1;
$page2->string($f2, $SIZE2, $COL2, 612 - 10 - $LINE2 * $SIZE2, $OUT);
}
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com