Make text wrap in a cell with FPDF?

Text Wrap: The MultiCell is used for print text with multiple lines. It has the same atributes of Cell except for ln and link. $pdf->MultiCell( 200, 40, $reportSubtitle, 1); Line Height: What multiCell does is to spread the given text into multiple cells, this means that the second parameter defines the height of each line … Read more

Special Characters in FPDF with PHP

Figured this out by doing the following (pagesubtitle is the name of the text field in the form): $reportSubtitle = stripslashes($_POST[‘pagesubtitle’]); $reportSubtitle = iconv(‘UTF-8’, ‘windows-1252′, $reportSubtitle); Then print it out: $pdf->Write (6, $reportSubtitle); This will remove any unwanted slashes following apostrophes, as well as use the ‘iconv’ function to print special characters such as ™

Inserting line breaks into PDF

If you are using fpdf, in order to be able to use line breaks you will need to use a multi-line text cell as described here. If you use this, then line breaks in your text should be interpreted and converted correctly. Just a quick example: $pdf->Multicell(0,2,”This is a multi-line text string\nNew line\nNew line”); Here, … Read more

FPDF error: Some data has already been output, can’t send PDF

For fpdf to work properly, there cannot be any output at all beside what fpdf generates. For example, this will work: <?php $pdf = new FPDF(); $pdf->AddPage(); $pdf->SetFont(‘Arial’,’B’,16); $pdf->Cell(40,10,’Hello World!’); $pdf->Output(); ?> While this will not (note the leading space before the opening <? tag) <?php $pdf = new FPDF(); $pdf->AddPage(); $pdf->SetFont(‘Arial’,’B’,16); $pdf->Cell(40,10,’Hello World!’); $pdf->Output(); … Read more

FPDF utf-8 encoding (HOW-TO)

Don’t use UTF-8 encoding. Standard FPDF fonts use ISO-8859-1 or Windows-1252. It is possible to perform a conversion to ISO-8859-1 with utf8_decode(): $str = utf8_decode($str); But some characters such as Euro won’t be translated correctly. If the iconv extension is available, the right way to do it is the following: $str = iconv(‘UTF-8’, ‘windows-1252’, $str);