Port participant signature page to use lpdf.php

Add required functions to lpdf.php to support the signature page
This commit is contained in:
james 2005-01-18 03:33:37 +00:00
parent f7d40b115a
commit 162475b62c
3 changed files with 139 additions and 105 deletions

View File

@ -36,7 +36,7 @@ class lpdf
pdf_moveto($this->pdf,$this->loc(0.5),$this->loc($this->yloc));
pdf_lineto($this->pdf,$this->loc(8),$this->loc($this->yloc));
pdf_stroke($this->pdf);
$this->yloc-=0.5;
$this->yloc-=0.20;
//now put a nice little footer at the bottom
$footertext=date("Y-m-d h:ia")." - ".$this->page_header." - ".$this->page_subheader;
@ -63,6 +63,101 @@ class lpdf
$this->addHeaderAndFooterToPage();
}
function vspace($space)
{
$this->yloc-=$space;
}
function setFontSize($size)
{
$this->currentFontSize=$size;
pdf_setfont($this->pdf,$this->normalfont,$size);
$leading=round($size*1.3);
pdf_set_value($this->pdf,"leading",$leading);
}
function addText($text,$align="left")
{
$fontsize=pdf_get_value($this->pdf,"fontsize",0);
$lineheight=ceil($fontsize*1.3);
//the line height should be 1.2 * fontsize (approx)
$stringwidth=pdf_stringwidth($this->pdf,$text,$this->normalfont,$fontsize);
$textstr=$text;
$nr=0;
$prevnr=0;
do
{
//echo "textstr=$textstr";
$len=strlen($textstr);
// echo "(lh:$lineheight nr:$nr len:$len)".$textstr;
$nl=false;
//now lets handle a newline at the beginning, just rip it off and move the yloc ourself
while($textstr[0]=="\n")
{
$textstr=substr($textstr,1);
$this->yloc-=$lineheight/72;
$nl=true;
}
if(!$nl)
$this->yloc-=$lineheight/72;
$nr=pdf_show_boxed($this->pdf,$textstr, $this->loc(0.75),$this->loc($this->yloc),$this->loc(7),$lineheight,$align,null);
if($nr==$prevnr)
{
echo "breaking becausae nr==prevnr ($nr==$prevnr) trying to output [$textstr]";
break;
}
$prevnr=$nr;
// printf("x=%f y=%f w=%f h=%f",$this->loc(0.75),$this->loc($this->yloc),$this->loc(7),$lineheight);
// echo "$nr didnt fit";
// echo "<br>doing: substr($textstr,-$nr) <br>";
$textstr=substr($textstr,-$nr);
// echo "nr=$nr";
} while($nr>0);
// pdf_rect($this->pdf,$this->loc(0.75),$this->loc($this->yloc),$this->loc(7),$height);
}
function addTextX($text,$xpos)
{
pdf_show_xy($this->pdf,$text,$this->loc($xpos),$this->loc($this->yloc));
}
function nextLine()
{
$this->yloc-=$this->currentFontSize*1.4/72;
}
function hr()
{
pdf_moveto($this->pdf,$this->loc(0.5),$this->loc($this->yloc));
pdf_lineto($this->pdf,$this->loc(8),$this->loc($this->yloc));
pdf_stroke($this->pdf);
$this->yloc-=0.25;
}
function hline($x1,$x2)
{
pdf_moveto($this->pdf,$this->loc($x1),$this->loc($this->yloc));
pdf_lineto($this->pdf,$this->loc($x2),$this->loc($this->yloc));
pdf_stroke($this->pdf);
}
function heading($text)
{
pdf_setfont($this->pdf,$this->headerfont,12);
pdf_show_xy($this->pdf,$text,$this->loc(0.5),$this->loc($this->yloc));
$this->yloc-=6/72; //half a line
pdf_setfont($this->pdf,$this->normalfont,$this->currentFontSize);
}
function addTable($table)
{
$height['tableheader']=0.2;

View File

@ -44,7 +44,7 @@ echo mysql_error();
{
if($r->status=="complete")
{
echo i18n("Congratulations, You are successfully registered for the %1",array($config['fairname']));
echo i18n("Congratulations, You are successfully registered for the %1. No further changes may be made to any of your forms.",array($config['fairname']));
}
else if($r->status=="paymentpending")

View File

@ -1,6 +1,7 @@
<?
require("common.inc.php");
include "register_participants.inc.php";
require("lpdf.php");
//authenticate based on email address and registration number from the SESSION
if(!$_SESSION['email'])
@ -33,26 +34,16 @@ echo mysql_error();
//END OF AUTH, now lets try to generate a PDF using only PHP :) this should be fun!
function loc($inch)
{
return $inch*72;
}
$pdf=new lpdf( i18n($config['fairname']),
i18n("Participant Signature Page"),
$_SERVER['DOCUMENT_ROOT'].$config['SFIABDIRECTORY']."/data/logo-200.gif"
);
$pdf=pdf_new();
pdf_open_file($pdf,null);
//Letter size (8.5 x 11) is 612,792
pdf_begin_page($pdf,612,792);
// pdf_set_parameter($pdf, "FontOutline", "Arial=/home/sfiab/www.sfiab.ca/sfiab/arial.ttf");
//$arial=pdf_findfont($pdf,"Arial","host",1);
$normalfont=pdf_findfont($pdf,"Times-Roman","host",0);
$headerfont=pdf_findfont($pdf,"Times-Bold","host",0);
pdf_set_info($pdf,"Author","SFIAB");
pdf_set_info($pdf,"Creator","SFIAB");
pdf_set_info($pdf,"Title","SFIAB - Participant Signature Page");
pdf_set_info($pdf,"Subject","Signature Form");
pdf_setlinewidth($pdf,0.3);
$pdf->newPage();
$height['sigspace']=0.50;
$pdf->setFontSize(11);
/*
//The title of the fair
$yloc=10.25;
$height['title']=0.25;
@ -60,24 +51,12 @@ echo mysql_error();
$height['topbox']=0.8;
$height['exhibitortitle']=0.2;
$height['exhibitorbox']=1.3;
$height['exhibitorsigspace']=0.40;
$height['exhibitorsigtext']=0.13;
$height['parenttitle']=0.2;
$height['parentbox']=2.80;
$height['parentsigspace']=0.40;
$height['parentsigtext']=0.13;
pdf_setfont($pdf,$headerfont,18);
pdf_show_boxed($pdf,$config['fairname'] ,loc(0.75),loc($yloc),loc(7),loc($height['title']),"center",null);
$yloc-=$height['title'];
pdf_setfont($pdf,$headerfont,14);
pdf_show_boxed($pdf,i18n("Signature Form"),loc(0.75),loc($yloc),loc(7),loc($height['subtitle']),"center",null);
$yloc-=$height['subtitle'];
pdf_moveto($pdf,loc(0.5),loc($yloc));
pdf_lineto($pdf,loc(8),loc($yloc));
pdf_stroke($pdf);
*/
//grab the project info
$q=mysql_query("SELECT * FROM projects WHERE registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."'");
@ -100,121 +79,81 @@ echo mysql_error();
$topboxtext.="$studentinfo->firstname $studentinfo->lastname, ";
}
//strip off the last comma
$pdf->heading(i18n("Registration Summary"));
$topboxtext=substr($topboxtext,0,-2);
//add the newline
$topboxtext.="\n";
// $topboxtext.="\n";
pdf_setfont($pdf,$normalfont,11);
pdf_set_value($pdf,"leading",15);
$pdf->addText($topboxtext);
$pdf->hr();
$pdf->heading(i18n("Exhibitor Declaration"));
$yloc-=$height['topbox'];
pdf_show_boxed($pdf,$topboxtext, loc(0.75),loc($yloc),loc(7),loc($height['topbox']),"left",null);
pdf_moveto($pdf,loc(0.5),loc($yloc));
pdf_lineto($pdf,loc(8),loc($yloc));
pdf_stroke($pdf);
pdf_setfont($pdf,$headerfont,12);
$yloc-=$height['exhibitortitle'];
pdf_show_xy($pdf,"Exhibitor Declaration",loc(0.5),loc($yloc));
pdf_setfont($pdf,$normalfont,11);
pdf_set_value($pdf,"leading",15);
$studentbox="The following section is to be read and signed by the exhibitor$plural\n\n".
$studentbox="The following section is to be read and signed by the exhibitor$plural.\n\n".
($plural?"We":"I")." certify that:\n".
" - The preparation of this project is mainly ".($plural?"our":"my")." own work\n".
" - ".($plural?"We":"I")." have read the rules and regulations and agree to abide by them\n".
" - ".($plural?"We":"I")." agree that the decision of the judges will be final\n";
$yloc-=$height['exhibitorbox'];
pdf_show_boxed($pdf,$studentbox, loc(0.75),loc($yloc),loc(7),loc($height['exhibitorbox']),"left",null);
$pdf->addText($studentbox);
foreach($studentinfoarray AS $studentinfo)
{
$yloc-=$height['exhibitorsigspace'];
$pdf->vspace($height['sigspace']);
//signature line
pdf_moveto($pdf,loc(1),loc($yloc));
pdf_lineto($pdf,loc(4.5),loc($yloc));
pdf_stroke($pdf);
$pdf->hline(1,4.5);
//date line
pdf_moveto($pdf,loc(5),loc($yloc));
pdf_lineto($pdf,loc(7),loc($yloc));
pdf_stroke($pdf);
$pdf->hline(5,7);
//go to next line
$pdf->nextLine();
$yloc-=$height['exhibitorsigtext'];
//show their name
pdf_show_xy($pdf,"$studentinfo->firstname $studentinfo->lastname (signature)",loc(1.25),loc($yloc));
$pdf->addTextX(i18n("%1 %2 (signature)",array($studentinfo->firstname,$studentinfo->lastname)),1.25);
//show the Date text
pdf_show_xy($pdf,"Date",loc(5.25),loc($yloc));
$pdf->addTextX(i18n("Date"),5.25);
//go to next line
$pdf->nextLine();
}
$yloc-=3*$height['exhibitorsigtext'];
pdf_moveto($pdf,loc(0.5),loc($yloc));
pdf_lineto($pdf,loc(8),loc($yloc));
pdf_stroke($pdf);
$pdf->hr();
//now for the parent/guardian signatures
pdf_setfont($pdf,$headerfont,12);
$yloc-=$height['parenttitle'];
pdf_show_xy($pdf,"Parent/Guardian Declaration",loc(0.5),loc($yloc));
pdf_setfont($pdf,$normalfont,11);
pdf_set_value($pdf,"leading",15);
$pdf->heading(i18n("Parent/Guardian Declaration"));
$parentbox="The following is to be read and signed by the exhibitor$plural parent$plural/guardian$plural.\n\n".
" - As a parent/guardian I certify to the best of my knowledge and believe the information contained in this application is correct, and the project is the work of the student. I also understand that the material used in the project is the responsibility of the student and that neither the school, the teacher, nor the ".$config['fairname']." can be held responsible for loss, damage, or theft, however caused. I further understand that all exhibits entered must be left on display until the end of the Fair. If my son/daughter does not remove the exhibit at the end of the Fair, the ".$config['fairname']." or the owner of the exhibition hall cannot be responsible for the disposal of the exhibit.\n\n".
" - If my son/daughter is awarded the honour of having his/her exhibit chosen for presentation at the Canada-Wide Science Fair, I consent to having him/her journey to the Fair, and will not hold the Fair responsible for any accident or mishap to the student or the exhibit.\n";
$yloc-=$height['parentbox'];
pdf_show_boxed($pdf,$parentbox, loc(0.75),loc($yloc),loc(7.0),loc($height['parentbox']),"left",null);
$pdf->addText($parentbox);
foreach($studentinfoarray AS $studentinfo)
{
$yloc-=$height['parentsigspace'];
$pdf->vspace($height['sigspace']);
//signature line
pdf_moveto($pdf,loc(1),loc($yloc));
pdf_lineto($pdf,loc(4.5),loc($yloc));
pdf_stroke($pdf);
$pdf->hline(1,4.5);
//date line
pdf_moveto($pdf,loc(5),loc($yloc));
pdf_lineto($pdf,loc(7),loc($yloc));
pdf_stroke($pdf);
$pdf->hline(5,7);
$pdf->nextLine();
$yloc-=$height['parentsigtext'];
//show their name
pdf_show_xy($pdf,"Parent/Guardian of $studentinfo->firstname $studentinfo->lastname (signature)",loc(1.25),loc($yloc));
$pdf->addTextX(i18n("Parent/Guardian of %1 %2 (signature)",array($studentinfo->firstname,$studentinfo->lastname)),1.25);
//show the Date text
pdf_show_xy($pdf,"Date",loc(5.25),loc($yloc));
$pdf->addTextX(i18n("Date"),5.25);
$pdf->nextLine();
}
//now put a nice little footer at the bottom
$footertext="Reg Num: ".$_SESSION['registration_number']." - Generated: ".date("Y-m-d h:ia")." - ".$config['fairname']." - ".$config['FAIRYEAR'];
$footerwidth=pdf_stringwidth($pdf,$footertext,$normalfont,9);
pdf_setfont($pdf,$normalfont,9);
pdf_show_xy($pdf,$footertext,loc(4.25)-$footerwidth/2,loc(0.5));
//footer line
pdf_moveto($pdf,loc(0.5),loc(0.7));
pdf_lineto($pdf,loc(8.0),loc(0.7));
pdf_stroke($pdf);
pdf_end_page($pdf);
pdf_close($pdf);
$pdfdata=pdf_get_buffer($pdf);
header("Content-type: application/pdf");
/*
header("Content-type: application/pdf");
header("Content-disposition: inline; filename=sfiab_sig_".$_SESSION['registration_id'].".pdf");
header("Content-length: ".strlen($pdfdata));
echo $pdfdata;
*/
echo $pdf->output();
?>