Huub said:
Sound like a nice solution. I read data from a MySQL database and print
it without changing font(size) etc. The layout itself is fine.
Could you give an example about how to include PCL into Perl?
The script below is an edited version of what I use. I have not tested
the edited version but it should give you some idea of one way to
accomplish this type of task. (The actual script is for CGI and creates
a web page which allows the user to upload a text file of label data,
you'll have to amend it for your needs, what follows below should read
label text from STDIN.
The input would be something like
label 1 line 1
label 1 line 2
label 2 line 1
label 2 line 2
label 2 line 3
label 3 line 1
I can't remember when exactly I wrote this but it clearly shows a *lot*
of my bad habits from Perl 4 days. therefore do *not* use it as an
eample of good style! Regulars of c.l.p.m may wish to point out it's
many many deficiencies. I'll grit my teeth and bear it
#!/usr/bin/perl
use strict;
use warnings;
#
# Avery J8163M labels are 14 per A4 sheet in two columns
# The distance from edge of page to the edge of the labels is:
# left: 4mm, top 14mm.
# There is no gap between labels vertically but there is a gap
# of about 3mm (1/10") between the two columns.
# The label dimensions are 99.1mm wide x 38.1mm high.
#
# Since PCL works in units of Inches or decipoints (1/720")
# The above are converted to
#
# left 0.1575" 113dp
# top 0.5512" 396dp
# gap 0.1000" 72dp
# width 3.9016" 2809dp
# height 1.5000" 1080dp
#
my $left = 50;
my $top = 450;
my $hgap = 72;
my $vgap = 0;
my $width = 2809;
my $height = 1080;
#
# We will not print at very edge of label but a few mm in from the edge
#
my $hinset = 144;
my $vinset = 144;
#
# We assume we are printing 6 lines per inch
#
my $lineheight = 720 / 6;
my $Esc = chr(27);
my $FormFeed = chr(12);
my $x = $left + $hinset;
my $y = $top + $vinset;
open (OUT, "|lp -d laserjet")
or die "(cannot print (lp -d laserjet) because $!\n";
pclstart();
my $count = 0;
my $row = 0;
while (<>) {
chomp;
if (/^\s*$/) { # move to top of next label
$count++;
$row++;
# move to top of next column?
if ($count == 7) {
$row = 0;
$x = $left + $width + $hgap + $hinset;
$y = $top + $vinset;
# start a new page?
} elsif ($count == 14) {
print OUT $FormFeed;
$count = 0;
$row = 0;
$x = $left + $hinset;
$y = $top + $vinset;
} else {
$y = $top + ($row * ($height + $vgap)) + $vinset;
}
} else {
print OUT "${Esc}&a${x}h${y}V$_"; # position text
$y = $y + $lineheight;
}
}
print OUT "${Esc}E"; # reset
close OUT;
exit;
sub pclstart {
print OUT "${Esc}E", # reset
"${Esc}&l0S", # Simplex (1 side per sheet)
"${Esc}&l2H", # Manual feed
"${Esc}&l26A", # A4
"${Esc}&k2G", # LF -> CR+LF
"${Esc}&l6D", # 6 lpi
"${Esc}&l0O", # Portrait
"${Esc}&l0E", # Top Margin (lines)
"${Esc}&l70F", # Text length (lines)
"${Esc}&a0L", # left Margin (columns)
"${Esc}(0N", # Character set: 0N = Latin 1
"${Esc}(s10v", # 10 point
"0s", # upright
"3b", # bold
"3t", # Courier
"2Q", # Letter Quality
"";
}