Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
06-24-2010, 04:09 PM
|
#1
|
|
Member
Registered: May 2008
Distribution: SuSe
Posts: 50
Rep:
|
Need script to generate vouchers
I have a file, two columns, first column has a list of 15000 (yes 15k) unique codes, second column has the afilliate codes of 60 locations repeated to fill out the 15000 rows of unique codes.
I need to produce a nice neat paper voucher which will fit onto A6 (1/4 A4) and is ready to print. Each voucher has the unique code and corresponding location.
So far I am thinking PHP will do the job. This does it somewhat, but doesn't let be split the fields between the ",".
I did this so far in PHP
Code:
<?
$fp = fopen('filein.csv','r') or die("can't open file");
print "<table>\n";
while($csv_line = fgetcsv($fp,1024)) {
print '<tr>';
for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
print '<td>'.$csv_line[$i].'</td>';
}
print "</tr>\n";
}
print '</table>\n';
fclose($fp) or die("can't close file");
?>
How can I make sure my formatting fits to A5?
|
|
|
|
06-24-2010, 10:43 PM
|
#2
|
|
Senior Member
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279
|
I would use imagemagick to create each file, so that you can specify the dimensions.
Alternatively, use htmldoc to create a pdf for each voucher, you can specify the page dimensions there too. You will have to experiment to get the correct alignment.
Both those tools can be scripted and sent commands from your script. I once used perl to create individual certificates in pdf format from database fields, running as a cgi script on a web server.
Last edited by smoker; 06-24-2010 at 10:47 PM.
|
|
|
|
06-25-2010, 05:40 AM
|
#3
|
|
Member
Registered: May 2008
Distribution: SuSe
Posts: 50
Original Poster
Rep:
|
I've now achieved what i want to do. Managed to get the list of afilliates re-organised thanks to some bash scripting. Took a while to get sed to play ball though. I don't think it likes variables that much!
Code:
for (( vet=1; vet<=60; vet++ )) ; do for (( repeat=1; repeat <=250; repeat++ )); do echo $vet; sed $vet'q;d' "populate.csv" >> newvetslist; done; done;
Code:
<?
$fp = fopen('filein.csv','r') or die("can't open file");
//print "<table border =1>\n";
while($csv_line = fgetcsv($fp,1024)) {
//print '<tr>';
for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
print '<center>Some html<BR></center>';
print '<center>';
if ($i=2)
{print 'Voucher Code: '.$csv_line[0].'';};
if ($i=1)
{print ' Affiliate Code: '.$csv_line[1].'';};
print '';
}
print '</center>';
print '<HR>';
//print "</tr>\n";
}
//print '</table>\n';
fclose($fp) or die("can't close file");
?>
finally did the job.
I hope its helpful to somebody.
|
|
|
|
06-25-2010, 10:13 AM
|
#4
|
|
Member
Registered: May 2008
Distribution: SuSe
Posts: 50
Original Poster
Rep:
|
Finally got it working, complete with page break every 3 pages
Code:
<STYLE>
DIV.pageBreak { page-break-before: always; }
</STYLE>
<?
//for (( vet=1; vet<=60; vet++ )) ; do for (( repeat=1; repeat <=250; repeat++ )); do echo $vet; sed $vet'q;d' "populate.csv" >> newvetslist; done; done;
$count = 0;
$fp = fopen('filein.csv','r') or die("can't open file");
while($csv_line = fgetcsv($fp,20)) {
for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
print '<BR><BR><HR>';
print '<center><img src=""><BR><font color="blue" size="5">URL</font></center>';
print '<center>Why not try ? <BR></center>';
print '<center>Text<BR></center>';
print '<center>Some text<BR></center>';
print '<center><b><font size="3" color="red">Some stuff</font></b><BR></center>';
print '<BR>';
print '<center>Just enter the following details at the checkout: <BR>';
if ($i=2)
{print 'Voucher Code <b> '.$csv_line[0].'</b>';};
if ($i=1)
{print ' Affiliate Code <b> '.$csv_line[1].'</b>';};
print '';
print '</center>';
print '<BR><HR>';
$count++;
if ($count==3) {print $count; print '<DIV CLASS="pageBreak"/>'; $count = 0; };
}
//if j=60, then output <DIV CLASS="pageBreak"/>.
}
fclose($fp) or die("can't close file");
?>
Last edited by suse_nerd; 06-25-2010 at 10:14 AM.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:33 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|