Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Greetings fellow monks,

Yesterday my lady asked me if I could do her a favor, gallant fool that I am I answered at once

"Of course, my paramour, it would be my honor to take on any quest, to slay any foe metaphorical or otherwise for your honor". For my defense the day before I forgot to make her lasagnas as promised and she was quite disappointed with my chicken and mushroom pie so that's why I did not ask what the task would be before accepting.

A strange activity was asked of me : writing raffle tickets with nice images in such a way that they could be easily printed and then cut out as individual tickets.
As more than 3 hundreds of them were required by 6 pm the same day (someone had dumped the task on her without warning) she told me that using Excel was a solution but as it was computer related she hoped I knew some wizardry to accomplish the task in mere moments.

So I grabbed my spear, shield, poleaxe, steed and my trusted GCC (gnu compiler cat, an universal syntax checker that will sit on my lap while I code and try to rip my throat if I move and sometimes when I make syntax mistakes)

I soon came up with this idea : Write it using latex, break the latex doc in discrete parts and then use a perl script to rearrange them as needed

Here is the resulting script : you give it a path to the image you want, the number of tickets you want and the scale for the image and you should (hopefully) get some kind of result.
Also you will need pdflatex.
As usual, I'm looking for ways to get better so constructive criticism is welcome.

Update: added autodie, thanks athanasius
use constant, rewrite the first loop, thanks anonymous monk, I'm going to read on the use of the DATA section


Aaaand another update, it's been a long time but I had to modify my script so it could do better:
Now you can pass more arguments: number of tickets in each column and output filename

#!/usr/bin/perl -w use strict; use autodie; use warnings; use Carp qw(croak); use Getopt::Std; sub main{ my ($image,$number,$scale,$COLS) = @_; my $header = '\documentclass[12pt]{report} \usepackage{graphicx} \usepackage{array} \usepackage{makecell} \usepackage[T1]{fontenc} \usepackage[margin=0.25in]{geometry} \usepackage[utf8]{inputenc} \begin{document} '; my $footer = '\end{document}'; open my $tombolatex, '>','int.tex'; print $tombolatex $header; my $body = '\begin{tabular}{'.('|c|' x $COLS).'} \hline'. (('\thead{Ticket} &'."\n") x ($COLS-1)). '\thead{Ticket}'."\n".'\\\\[6ex] \hline'. (('\makecell{\includegraphics[scale=ISCALE]{image}\\\\ Ticket} &'."\n" +)x ($COLS-1)). '\makecell{\includegraphics[scale=ISCALE]{image}\\\\ Ticket} \\\\[12ex +] \hline \end{tabular} '; print $tombolatex $body x (1 + $number / $COLS); print $tombolatex $footer; close $tombolatex; open $tombolatex, '>','res.tex'; open my $input,'<','int.tex'; my $tn = 1; my $iter = 0; my $find = 'Ticket'; $find = quotemeta $find; while(<$input>){ my $replace = "Ticket $tn"; my $line= $_; $line=~s/image/$image/g; $line =~s/ISCALE/$scale/g; if($line =~ s/$find/$replace/g){ if($tn % $COLS == 0){ if($iter == 1){ $tn++; $iter = 0; } else{ $tn -= ($COLS-1); $iter++; } } else{ $tn++; } } print $tombolatex $line; } } our ($opt_i,#image switch $opt_n,#number of tickets $opt_s,#image_scale $opt_c,#number of columns $opt_o);#output filename getopts('i:n:s:c:o:'); my @shortargs= ($opt_i,$opt_n,$opt_s,$opt_c,$opt_o); if(!defined($shortargs[0])|| !defined $shortargs[1] || !defined $shortargs[2]|| !defined $shortargs[3]||!defined $shortargs[4]){ croak <<"END" -i image to put on tickets: $shortargs[0] -n number of tickets: $shortargs[1] -s image scale: $shortargs[2] -c number of columns: $shortargs[3] -o filename: $shortargs[4] END } main @shortargs; `pdflatex res.tex`; unlink 'int.tex'; rename 'res.pdf', $shortargs[4]; my @res = glob "res.*"; unlink @res;

In reply to raffle_tickets_generator by QuillMeantTen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-03-29 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found