0

I am trying to generate pdf using fpdf library and php .

I want to pdf output like :

------------               -------------
 Grad Marks                90%
 Documnets attched         Mark Sheet, I.C. or TC, Caste
                           Certificate, Eligibility Form, Bonafide,
                           Passing Certificate
 Why do you want to        Because I want to build my career
 take  admission in        in management field.
 MBA?

So I have written a piece of code

$pdf = new FPDF();
$pdf->AddPage();
foreach ($userInputs as $key => $value) {
 $pdf->Ln(7);
            $pdf->SetFont('Helvetica', 'B', 10);
            $pdf->MultiCell(90.5, 2.7, $key, 0, 'L', false);
            $pdf->SetFont('Helvetica', '', 10);
            $pdf->MultiCell(60, 2.7, $value, 0, 'L', false);
        }
    }
$pdf->Output();

N:B - Where $userInput is an array contains (Grad Marks,Documnets attched, Why do u ...) as key and (90%,Marks sheet..., Because I want ...) as values.

But I am not getting the desired output. I am getting out put like

------------              
 Grad Marks                
 90%
 Documnets attched         
 Mark Sheet, I.C. or TC, Caste
 Certificate, Eligibility Form, Bonafide,
 Passing Certificate
 Why do you want to 
 take  admission in        
 MBA?
 Because I want to build my career
 in management field.

So please help me out to get the desired output.

Thanks in advance.

Sam
  • 1,033
  • 3
  • 16
  • 25
  • This has been previously answered on StackOverflow. Check out [this question](http://stackoverflow.com/questions/13559330/fpdf-print-multicell-adjacently) for how to get it to work. – Ken Herbert Jun 14 '13 at 07:23
  • It's working but I found pagebreaks in cells. So please suggest me how to fix the issue. – Sam Jun 14 '13 at 07:47
  • I've come across that issue before, but there is no way to prevent it without changing the source of FPDF. I'm not at work to access the code changes I made, but I'm pretty sure I just copied the `MultiCell` function within the source, renamed it to `GetMultiCellHeight` and removed everything in the function except the bits where it calculated the cell height. Then you just need to call `$pdf->GetMultiCellHeight(content)` and check to see if enough space remains on the page. If not add a page break, then finally call `$pdf->MultiCell(content)`. – Ken Herbert Jun 14 '13 at 07:53

1 Answers1

0

please take a look at example of using writeHTML() function at http://www.fpdf.org/en/script/script41.php

then try something like this

$pdf = new PDF_HTML();
$pdf->AddPage();
$html ='<table>';
foreach ($userInputs as $key => $value) {
   html.='<tr><td>$key</td><td>$value</td></tr>';  
}
$html .= '</table>';
$pdf->Output();
Hilarius L. Doren
  • 757
  • 1
  • 12
  • 29