ProgrammingThis 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.
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");
?>
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.