PostScript::LabelSheet - print multiple labels on a sheet, starting from PostScript label template.
use PostScript::LabelSheet; my $sheet = new PostScript::LabelSheet; $sheet->columns(3); # 3 labels abreast $sheet->rows(10); # on 10 rows # Or specify the dimensions of the labels, in PostScript points # $sheet->label_width(...); $sheet->label_height(...); $sheet->skip(5); # leave 5 labels blank $sheet->add('/path/to/label_1.eps', 5); $sheet->add('/path/to/label_2.eps', 3); $sheet->add('/path/to/label_3.eps'); $sheet->fill_last_page(1); # label_3 will fill the last sheet. print $sheet->as_postscript();
I sometimes have to print a sheet of labels, each label bearing the same design, for example to label jars of marmelade. I tried to do this with OpenOffice.org writer, in a table. But I had to manually copy and paste the design of the first label into every cell, and of course, if I changed the design, the changes had to be reported manually to the other cells. And of course, changing the dimensions, or adding a column or a row, need some manual intervention.
This module is here to easily print a sheet (or sheets) of labels representing a repeating pattern. Give it a design in Encapsulated PostScript (EPS), how many labels you want, how big they should be or how many should fit in the width and heigth of the page, and PostScript::LabelSheet generates the PostScript code for you, which you can then directly print.
There are options to print several kinds of labels on the same sheet, each with its own design, to draw a grid around the labels for cutting them, and to control how they are laid out on the page.
Additionally, labels can be numbered. This can be useful to print numbered tickets for a local event for instance.
Use inkscape (http://www.inkscape.org) to draw the design that you want to print on each label. Keep the original in the SVG format, and export it as Encapsulated PostScript for use with PostScript::LabelSheet.
The size of the design is unimportant, as this is vector graphics, the generated PostScript program will resize without losing quality so that it fits within a label. What is important, however, is that the design occupies all the space on the page. The easiest is to draw without giving any thought to the page, then adjust the page size to the drawing. In inkscape, you can use the Document Properties dialog box to let the page fit the design exactly (menu File, Document Properties, in the Page tab, click the "Fit page to selection" button).
To save the design in EPS format, in inkscape, go to menu File, Save a copy, and choose the "
Encapsulated PostScript (*.eps)" format. Inkscape will show a dialog with options for the conversion to EPS. Do check the box "Make bounding box around full page", so that the generated EPS code contains information about the size of the design. PostScript::LabelSheet needs it to work out the scale at which the design should be included on the page.
Returns a new instance of PostScript::LabelSheet with all its attributes set to the built-in default values.
The following methods are accessors when given no argument, and mutators when given one. As accessor they return the corresponding attribute's value:
As mutators, they set the attribute's value, and return the PostScript::LabelSheet instance itself, making it possible to stack several calls to mutators:
my $sheet = PostScript::LabelSheet->new() ->width(595) ->height(842) ->grid(0) ;
Give the number of columns and rows in which the labels should be laid out on each page. The labels width and height will be calculated accordingly.
Give the width and height of each label. The program will automatically calculate how many labels will fit on each row and column.
Either columns() or label_width(), and either row() or label_height(), must be specified before invoking as_postscript().
Set this option to a true value to have the last label repeat until the end of the last page.
Dimensions of the page. Default to DIN A4 (210 × 297 mm).
Vertical (top and bottom) and horizontal (left and right) margins. Default to 5 mm. Use margin() to set both v_margin() and h_margin() at the same time. It is not possible to set the top margin independantly from the bottom margin, nor the left margin independantly from the right one.
Space left blank inside each label and around the design within. Default to 0. Use padding() to set both h_padding() and v_padding() at the same time.
Space between columns (h_spacing()) or rows (v_spacing()) of labels. Default to 0 (no space between rows and columns). Use spacing() to set both h_spacing() and v_spacing() at the same time.
Number of labels to leave blank at the top of the first page. The default is to start at the top left of the page.
If set to a true value, the designs are rotated 90 degrees clockwise inside each label. Default to false.
If set to a true value, a grid is drawn around the labels. This is the default.
Adds a design to the sheet of labels. PATH is the path to a file in the Encapsulated PostScript format. See the "Drawing the design" section above for hints on how to make such a file. COUNT is optional and defaults to 1. However, it fill_last_page() is set to a true value, the last design will be repeated until the end of the last page.
Returns the instance of the PostScript::LabelSheet object, so calls can be stacked:
$sheet->add('file1.eps', 5) ->add('file2.eps', 6) ->add('file3.eps', 4) ;
Returns the number labels that would fit on a page.
Returns the number of labels printed on all the pages. If fill_last_page() is set to a true value, this might not reflect the number of labels actually printed, as the last one will be printed multiple times. The number will be accurate after the PostScript has been generated in a call to as_postscript(), as the count property of the last design will be adjusted at that moment.
A rewrite of Class::Accessor's set() mutator, that returns the instance of the object, instead of the value.
Sets both h_margin() and v_margin() to SIZE at the same time, and respectively for h_padding() and v_padding(), and for h_spacing() and v_spacing().
Returns the PostScript code that prints the labels. It can be sent directly to a printer spool, or converted to PDF, or whatever you can do with PostScript.
<cbouvi at cpan.org>
Please report any bugs or feature requests to
bug-postscript-labelsheet at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PostScript-LabelSheet. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
You can also look for information at:
Copyright 2009 Cédric Bouvier.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.