Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7850067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:43:56+00:00 2026-06-02T18:43:56+00:00

I am trying to construct a PDF table with fPDF and PHP and it

  • 0

I am trying to construct a PDF table with fPDF and PHP and it creates a table if it fits one page. However if the table does not fit in one page, although the first page is good, on the second page and on the other pages the table is not regular. Here is an example of my pdf output:

https://rapidshare.com/files/486723233/results.pdf

And here is my code for create this table:

//FILL THE TABLE

            $max_number_of_lines = 0;

            for ($index = 0; $index < count($subjects); $index++,$temp=0,$row_height = 15,$max_number_of_lines = 0) {
                //Account height of row, all will be same
                //Issue a page break first if needed
                if($this->GetY()+$row_height > $this->PageBreakTrigger)
                    $this->AddPage($this->CurOrientation);

                foreach ($subjects[$index] as $fields) {
                    $myString = mb_convert_encoding($fields, "iso-8859-9", "auto");
                    $number_of_lines = ceil(($this->GetStringWidth($fields))/$fieldLengthArray[$temp]);
                    if ($row_height < ceil($number_of_lines * 15)) {
                        $row_height = ceil($number_of_lines * 15);
                        $max_number_of_lines = $number_of_lines+1;
                    }
                    $temp++;
                }
                $temp=0;
                foreach ($subjects[$index] as $myFields) {
                    //$this->SetAutoPageBreak(true,$row_height);
                    $this->SetY($currentY);
                    $this->SetX($currentX);
                    $myString = mb_convert_encoding($myFields, "iso-8859-9", "auto");
                    $number_of_lines = ceil(($this->GetStringWidth($myFields))/$fieldLengthArray[$temp]);

                    if ($number_of_lines < $max_number_of_lines-1) {
                        $this->Rect($currentX, $currentY, $fieldLengthArray[$temp], $row_height);   
                        //Draw the border
                        //$this->Rect($x, $y, $w, $h);
                        $this->MultiCell($fieldLengthArray[$temp], ceil($row_height/$max_number_of_lines) , 
                            $myString,0,  'L', $fill);

                    }
                    else {
                        //Draw the border
                        //$this->Rect($x, $y, $w, $h);
                        $this->Rect($currentX, $currentY, $fieldLengthArray[$temp], $row_height);   
                        $this->MultiCell($fieldLengthArray[$temp], ceil($row_height/$max_number_of_lines), 
                            $myString,0,  'L', $fill);

                    }
                    $currentX += $fieldLengthArray[$temp];
                    $temp++;
                    //$this->Ln();
                }
                $this->Ln($row_height);
                $this->SetY($currentY);
                $currentX = $this->GetX();
                $currentY += $row_height;

            }
            $this->SetFillColor(238);
            $this->SetLineWidth(0.2);
            $this->SetFont('arial_tr', '', 10);
            $this->Ln();
        }

It is part of my function, Generate table and $subjects is the information i get from database.

$subjects = array(array()) 

I couldn’t understand why it is not regular in the second and other pages when it is regular on first page. I also check for end of the page.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:43:57+00:00Added an answer on June 2, 2026 at 6:43 pm

    It’s happening because with one cell you’re triggering a page break in the page.

    Either you disable in the fpdf the “auto page break” or you have to calculate in advance the height of the cells for one row.

    As an alternative you can check out my fpdf table script:
    http://interpid.eu/fpdf-table

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to construct a table on the right of the page where I
I'm trying construct a PostgreSQL query that does the following but so far my
I'm trying to construct a table with Prototype's New Element function. I was experiencing
I am trying to construct a rule-based system for interpreting data. However, I am
I am trying to construct a DateTime in C# one step at a time,
I'm trying to construct a table with dynamically build information. My thought was to
I am trying to download multiple PDF files as one zip file and then
I'm trying to construct a page layout that will look something like this: In
I am trying to construct a device which will do one thing for a
I am trying to construct a page layout, where the left column has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.