summaryrefslogtreecommitdiff
path: root/sheetprint
diff options
context:
space:
mode:
authorcos <cos>2015-01-25 22:41:27 +0100
committercos <cos>2015-01-25 22:41:27 +0100
commit6a2878a7ddbb4fc6522d694af62e1743da0c872f (patch)
treeb0925b8e99c01b88ae950569952e9f29430e0745 /sheetprint
parent9f3a16ce5f3b036f5d46c10c64bd346bbdcf6478 (diff)
downloadmat-6a2878a7ddbb4fc6522d694af62e1743da0c872f.zip
Initial commit of sheetprint script.
Diffstat (limited to 'sheetprint')
-rwxr-xr-xsheetprint73
1 files changed, 73 insertions, 0 deletions
diff --git a/sheetprint b/sheetprint
new file mode 100755
index 0000000..5ee0a38
--- /dev/null
+++ b/sheetprint
@@ -0,0 +1,73 @@
+#!/usr/bin/perl
+#
+# Sometimes it is handy to print an a4 sheet of labels through a regular
+# printer, rather than using a dedicated label printer. This script kind of
+# makes it possible.
+#
+# Add something like this line to /etc/mat.conf first:
+# print_command "mv /usr/local/mat/label.png /usr/local/mat/label-`date +%s`.png"
+
+use strict;
+use warnings;
+
+use GD;
+
+use constant DPI => 300;
+
+sub mm2dots
+{
+ my ( $mm ) = @_;
+
+ return ($mm/2.54/10*DPI);
+}
+
+my $a4 = new GD::Image(210/2.54/10*DPI, 297/2.54/10*DPI);
+my $white = $a4->colorAllocate(255,255,255);
+my $black = $a4->colorAllocate(0,0,0);
+$a4->fill(0, 0, $white);
+
+# Draw a cross
+$a4->line(0, 0, $a4->width(), $a4->height, $black);
+$a4->line($a4->width(), 0, 0, $a4->height, $black);
+
+# Draw some rulers
+for ( my $i = 1; $i < 297; $i++) {
+ if ( $i % 10 == 0 ) {
+ $a4->line(0, mm2dots($i), 20, mm2dots($i), $black);
+ $a4->line(mm2dots(105), mm2dots($i), mm2dots(105) + 20, mm2dots($i), $black);
+ } elsif ( $i % 5 == 0 ) {
+ $a4->line(0, mm2dots($i), 15, mm2dots($i), $black);
+ $a4->line(mm2dots(105), mm2dots($i), mm2dots(105) + 15, mm2dots($i), $black);
+ } else {
+ $a4->line(0, mm2dots($i), 10, mm2dots($i), $black);
+ $a4->line(mm2dots(105), mm2dots($i), mm2dots(105) + 10, mm2dots($i), $black);
+ }
+}
+for ( my $i = 1; $i < 210; $i++) {
+ if ( $i % 10 == 0 ) {
+ $a4->line(mm2dots($i), mm2dots(297), mm2dots($i), mm2dots(297) - 20, $black);
+ $a4->line(mm2dots($i), mm2dots(149), mm2dots($i), mm2dots(149) - 20, $black);
+ } elsif ( $i % 5 == 0 ) {
+ $a4->line(mm2dots($i), mm2dots(297), mm2dots($i), mm2dots(297) - 15, $black);
+ $a4->line(mm2dots($i), mm2dots(149), mm2dots($i), mm2dots(149) - 15, $black);
+ } else {
+ $a4->line(mm2dots($i), mm2dots(297), mm2dots($i), mm2dots(297) - 10, $black);
+ $a4->line(mm2dots($i), mm2dots(149), mm2dots($i), mm2dots(149) - 10, $black);
+ }
+}
+
+my $x = mm2dots(25);
+my $y = mm2dots(30);
+
+for my $filename ( `ls label-??????????.png` ) {
+ my $label = GD::Image->newFromPng($filename);
+ $a4->copy($label, $x, $y, 0, 0, $label->width(), $label->height());
+ $y += mm2dots(30);
+}
+
+open(PNGFILE, ">a4.png");
+print PNGFILE $a4->png;
+
+my $density = DPI * 1/2.54;
+
+system("convert -density $density -define pdf:fit-page=A4 a4.png a4.pdf");