I restored my backup of the certificate.php file but I'm feeling squeamish about trying this again since my knowledge of PDF generation could fill a thimble.
I'm pasting my certificate.php code as it is below (this is without the modifications of adding margins, etc.) So how can I wrap the text of the course title without making a bigger mess than I have today?
// Add text
$pdf->SetTextColor(0,0,120);
$pdf->SetLeftMargin(30);
$pdf->SetRightMargin(30);
cert_printtext(170, 125, 'C', 'Helvetica', 'B', 30, utf8_decode(get_string('titlevoice1', 'certificate')));
$pdf->SetTextColor(0,0,0);
cert_printtext(170, 180, 'C', 'Times', 'B', 20, utf8_decode(get_string('introvoice1', 'certificate')));
cert_printtext(170, 230, 'C', 'Helvetica', '', 30, utf8_decode($studentname));
cert_printtext(170, 280, 'C', 'Helvetica', '', 20, utf8_decode(get_string('statementvoice1', 'certificate')));
cert_printtext(170, 330, 'C', 'Helvetica', '', 20, '');
$pdf->Write(20,utf8_decode($course->fullname));
cert_printtext(170, 330, 'C', 'Helvetica', '', 20, utf8_decode($classname));
cert_printtext(500, 520, 'C', 'Helvetica', '', 14, utf8_decode($certificatedate));
cert_printtext(170, 420, 'C', 'Times', '', 10, utf8_decode($grade));
cert_printtext(170, 431, 'C', 'Times', '', 10, utf8_decode($outcome));
cert_printtext(170, 442, 'C', 'Times', '', 10, utf8_decode($credithours));
cert_printtext(170, 500, 'C', 'Times', '', 10, utf8_decode($code));
$i = 0 ;
if($certificate->printteacher){
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if ($teachers = get_users_by_capability($context, 'mod/certificate:printteacher', '', $sort='u.lastname ASC','','','','',false)) {
foreach ($teachers as $teacher) {
$i++;
cert_printtext(130, 440+($i *12) , 'L', 'Times', '', 12, utf8_decode(fullname($teacher)));
}}}
cert_printtext(150, 450, '', '', '', '', '');
$pdf->SetLeftMargin(130);
$pdf->WriteHTML($customtext);
?>
I assume that:
cert_printtext(170, 330, 'C', 'Helvetica', '', 20, utf8_decode($classname));
is the line that is killing you?
If so, try php wordwrap......something like this (placed above this $classname):
$classname = wordwrap($classname, 100, "<br />\n");
will make the name wrap (in this example at 100 characters).
Here is some more info: http://php.net/manual/en/function.wordwrap.php/span>
Then....you will have to move the next line down a bit:
cert_printtext(130, 440+($i *12) , 'L', 'Times', '', 12, utf8_decode(fullname($teacher)));
}}}
to maybe:
cert_printtext(130, 480+($i *12) , 'L', 'Times', '', 12, utf8_decode(fullname($teacher)));
}}}
as the wrapping line will now fall lower on the page.
cert_printtext(170, 330, 'C', 'Helvetica', '', 20, utf8_decode($classname));
ah....ok, the PDF printing is ignoring the <br/> tags
try this:
First (make it break?):
$classname = wordwrap($classname, 100, "<br>\n");
See if just a <br> tag, not <br/> is caught (longshot and we break xhtml here)
Or...If that still doesn't work try this (assuming here we only need to get to 200 characters):
//ABOVE THE PRINT CODE
if (strlen ($classname>99)){ //classname over 99 characters
$classname1 = substr($classname, 0, 99); //first 99 charsacters
$classname2 = substr($classname, 100); //charaters 100+
}
//IN THE PRINT CODE
if ($classname1) {
cert_printtext(170, 330, 'C', 'Helvetica', '', 20, utf8_decode($classname1));
}
else {
cert_printtext(170, 330, 'C', 'Helvetica', '', 20, utf8_decode($classname));
}
same for classname2......
Ken
This just gets more and more baffling....but thank you so much for trying to help. I put in the code above just as you said. (I'm attaching the file so you can see I'm not a complete spazz.) ;) The only thing I changed was from 99 to 75 because I'm trying to do it for 75 characters instead.
It's still not breaking at all, so I'm guessing it's triggering the else statement somehow...?
try
if(strlen($classname)>99) ...
instead of
if(strlen($classname>99)) ...
It works. I'm sure my code is ugly...I had to make a few other mods. But I'm posting it in case anybody wants to see it.
Now this is purely hypothetical....and probably nightmarish to ask. Is there an easy way I could do this so that it would only break on a space instead of in the middle of a word? I seem to remember doing that a long time ago in a galaxy far away in my PHP class....maybe...
I'm just so happy that this works for now...I didn't want to have to redo 300+ certs by hand.
The certificate module (to be precise: the lib.php therein) only uses the simple Cell-function from the tcpdf-library.
I modified my certificate/lib.php in a way that I can use those multicell-functions in the certificate-types.
I needed this, because I wanted an abstract of the course contents to be printed onto the certificate. I had to add some extra fields to the database and to the user-form too.
If you just need some text bits to be wrappable, adding a cert_printmultitext function to the library may help.
Sorry for the missed bracket (thanks Raymond for the catch). The Code I posted also cuts the classname at 100 characters regardless (should have posted this...see below).
//------ABOVE THE PRINT CODE------
$classname = wordwrap($classname, 75, "<br />\n"); //wrap at 75 characters
//Pull out text before and after the <br /> in the wrap
if ($pos = strpos($classname, "<br />")){ //look for the <br/>
$classname1 = substr($classname, 0, $pos); //make $classname1 everything before that <br/>
$classname2 = substr($classname, $pos+5); //make $classname2 everything after that <br/> - the $pos+5 is 5 characters past start of <br/>
}
//------IN THE PRINT CODE-------
if ($classname1) {
cert_printtext(170, 330, 'C', 'Helvetica', '', 20, utf8_decode($classname1));
}
else {
cert_printtext(170, 330, 'C', 'Helvetica', '', 20, utf8_decode($classname));
}
if ($classname2) {
cert_printtext(170, 370, 'C', 'Helvetica', '', 20, utf8_decode($classname2));
}