0
  • I have created and successfully created my pdf file in php with fpdf library support.

  • But the problem is my footer is showing more space.

  • I want to reduce the space underneath my text. My output is like this: output

Here my code goes:

<?php
    require('fpdf/fpdf.php'); 
    class PDF extends FPDF {


                function Header() {
                            $this->SetY(0.208333);
                        }
                function Footer() {
                                 if ($this->footer <> 1)
                                 {
                                $this->SetY(-15);
                             }
                             else
                             {
                                echo "bye";
                             }
                        }
    }

                        //class instantiation
                        $pdf=new PDF("l","in",array(8.5,4.17));
                            $pdf->SetFont('Arial','',8);
                            $pdf->footer = -15;
                            //Array2
                            $datas = array
                                    (
                                    'Address1' => array
                                    (
                                    'Name' => 'Vijaya',
                                    'Area' => 'Valasaravakkam',
                                    'City' => 'Chennai',
                                    ),
                                    'Address2' => array
                                    (
                                    'Companyname' => 'Vy Systems',
                                    'Area' => 'Valasaravakkam',
                                    'City' => 'Chennai',
                                    ),
                                    'Address3' => array
                                    (
                                    'Companyname' => 'Vy Systems1',
                                    'Area' => 'Valasaravakkam1',
                                    'City' => 'Chennai1',
                                    ),
                                    );
                            //Array2
                            $datas1 = array
                                    (
                                    'Address4' => array
                                    (
                                    'Name' => 'Jaya',
                                    'Area' => 'Valasaravakkam',
                                    'City' => 'Chennai',
                                    ),
                                    );

                            foreach($datas1 as $address1 => $details1)
                            {
                                //pdf_set_text_pos($pdf, 1240, 490);
                                //$pdf->ln(1);

                                    foreach($datas as $address => $details)
                                    {
                                        $pdf->SetMargins(0,0,0.3);
                                        $pdf->AddPage();
                                        if((is_array($details)) and (is_array($details1)))
                                        {
                                            foreach($details1 as $rows1 => $value1)
                                            {
                                                $pdf->SetX(0.520833);
                                                $pdf->MultiCell(0, 0.2, $value1, 0, "L");
                                            }
                                            $pdf->ln(1.96);
                                            foreach($details as $rows => $value)
                                            {
                                                $pdf->SetX(5);
                                                $pdf->MultiCell(5, 0.2, $value, 0, "L");
                                            }
                                        }

                                    }//end of sub foreach
                            }//end of main foreach

                        $pdf->Output();
?>

1 Answer 1

1

I didn't follow the code completely, but it seems you're using the Header and Footer methods to set Y and nothing more, expecting that to be enough to correctly position the MultiCells being output outside of the Header and Footer. Maybe so, but the interaction of positioning inside and outside the Header/Footer isn't well defined.

For example, the process may be something like this: Y is calculated for the MultiCell, that trips the footer, the footer changes Y, the MultiCell is output. Is this the original Y, the revised (by the footer Y), or some other value? Absent a precise definition of what happens, you've set up a complex sequence of things that would be very difficult to sort out.

I would suggest vastly simplifying the code. You may find that the automatic header/footer tripping isn't helpful at all. In that case, turn off the auto page break, get rid of the Footer/Header functions, and totally control each page yourself. That way at least you have a clear, reliable model of what's going on.

1
  • I think i got some ideas through your answer.Will try on it and let you know. Jan 7, 2013 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.