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 8620403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:34:18+00:00 2026-06-12T06:34:18+00:00

Im using mPDF to generate PDFs and send reports to the clients. I’m using

  • 0

Im using mPDF to generate PDFs and send reports to the clients.

I’m using this foreach to fill my table row

    $report_nr = $this->input->post('report_nr');
        $date = $this->input->post('date');
        $owner = $this->input->post('owner');
        $ar1 = $this->input->post('column01');
        $ar2 = $this->input->post('column02');
        $ar3 = $this->input->post('column03');
        $ar4 = $this->input->post('column04');
        $ar5 = $this->input->post('column05');
        $ar6 = $this->input->post('column06');
        $ar7 = $this->input->post('column07');
        $ar8 = $this->input->post('column08');
        $ar9 = $this->input->post('column09');
        $ar10 = $this->input->post('column10');

        include('../mpdf.php');
        $mpdf = new mPDF('',    // mode - default ''
            'A4',    // format - A4, for example, default ''
            0,     // font size - default 0
            '',    // default font family
            15,    // margin_left
            15,    // margin right
            16,     // margin top
            16,    // margin bottom
            9,     // margin header
            9,     // margin footer
            'P');  // L - landscape, P - portrait
        //$this->customer_report();
        $n=0; //start counting at 0, like array counters do.
        foreach ($ar2 as $thing) { //for each value of $ar2
        $bigar[$n][2] = $thing; //set $bigarray at $n at 1 to that part
        $n++; //add one to $n, continue
        }
        $n=0; //repeat for array 3
        foreach ($ar3 as $thing) {
        $bigar[$n][3] = $thing; //now use the 2 value of the array
        $n++;
        }
        $n=0; //repeat for array 4
        foreach ($ar5 as $thing) {
        $bigar[$n][5] = $thing; //now use the 2 value of the array
        $n++;
        }
        $n=0; //start counting at 0, like array counters do.
        foreach ($ar6 as $thing) { //for each value of $ar2
        $bigar[$n][6] = $thing; //set $bigarray at $n at 1 to that part
        $n++; //add one to $n, continue
        }
        $n=0; //repeat for array 3
        foreach ($ar8 as $thing) {
        $bigar[$n][8] = $thing; //now use the 2 value of the array
        $n++;
        }
        $n=0; //repeat for array 4
        foreach ($ar9 as $thing) {
        $bigar[$n][9] = $thing; //now use the 2 value of the array
        $n++;
        }
        $n=0; //repeat for array 1
        foreach ($ar1 as $thing) {
        $bigar[$n][1] = $thing; //now use the 2 value of the array
        $n++;
        }
        $this->mpdf->WriteHTML("<table border='1'>");
        $this->mpdf->WriteHTML('<thead><tr><th class="span1">Relatório Nº :</th><th>&nbsp;'.$report_nr.'&nbsp;</th><th>Data :</th><th>&nbsp;'.$date.'&nbsp;</th><th>Cliente :</th><th colspan="5">&nbsp;'.$owner.'&nbsp;</th></tr></thead>');
        $this->mpdf->WriteHTML("<tbody>");
        $this->mpdf->WriteHTML("<tr>");
        foreach ($bigar as $part) { //go through each chunk of the array
          if($i%10 == 0 && $i != 0) { 
            $this->mpdf->WriteHTML("</tr>");
            $this->mpdf->WriteHTML("<tr>");
          }
        $this->mpdf->WriteHTML("<td>");
        $this->mpdf->WriteHTML("<table><tbody><tr><td>&nbsp;".($part[2]+$part[3])."&nbsp;</td><td>&nbsp;".($part[5]+$part[6])."&nbsp;</td><td>&nbsp;".($part[8]+$part[9]).'&nbsp;</td></tr><tr><td colspan="3">&nbsp;'.$part[1]."&nbsp;</td></tr></tbody></table>");
        $this->mpdf->WriteHTML("</td>"); //now, like above, that part has [1], and [2]
        $i++;
        }
        $this->mpdf->WriteHTML("</tr>");
        $this->mpdf->WriteHTML("</tbody></table>");

As u can see on the last row…when i reach 10 cells, it create another row.
Now i need the last row to get to 10 cells even if no content on the arrays, otherwise it won’t create the complete row, which makes my table a mess in the end…

Here’s a printscreen of the pdf:

PrintScreen

Hope i made myself clear.

Thank you all

  • 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-12T06:34:19+00:00Added an answer on June 12, 2026 at 6:34 am

    Found a way of doing it and i want to share with u.

        }
        $this->mpdf->WriteHTML('<table border="1">');
        $this->mpdf->WriteHTML('<thead><tr><th>Relatório Nº :</th><th>&nbsp;'.$report_nr.'&nbsp;</th><th>Data :</th><th>&nbsp;'.$date.'&nbsp;</th><th>Cliente :</th><th colspan="5">&nbsp;'.$owner.'&nbsp;</th></tr></thead>');
        $this->mpdf->WriteHTML("<tbody>");
        $this->mpdf->WriteHTML("<tr>");
        foreach ($bigar as $part) { //go through each chunk of the array
          if($i%10 == 0 && $i != 0) { 
            $this->mpdf->WriteHTML('</tr>');
            $this->mpdf->WriteHTML('<tr>');
          }
    
        $this->mpdf->WriteHTML("<td>");
        $this->mpdf->WriteHTML("<table border='1'><tbody><tr><td>&nbsp;".($part[2]+$part[3])."&nbsp;</td><td>&nbsp;".($part[5]+$part[6])."&nbsp;</td><td>&nbsp;".($part[8]+$part[9]).'&nbsp;</td></tr><tr><td colspan="3">&nbsp;'.$part[1]."&nbsp;</td></tr></tbody></table>");
        $this->mpdf->WriteHTML("</td>"); //now, like above, that part has [1], and [2]
    
    
        $i++;
    
        }
        $this->mpdf->WriteHTML('<td colspan="'.(10-($i%10)).'"></td></tr>');
        $this->mpdf->WriteHTML("</tbody></table>");
        //$bigar_removed = ereg_replace("0", "", $bigar);
        //$this->mpdf->WriteHTML("".$bigar_removed."");
            $this->mpdf->WriteHTML("<pagebreak>");
    
            $this->mpdf->Output();
            exit;
        }
    

    The trick was find a way of know which cell number was last created in the row.

        $this->mpdf->WriteHTML('<td colspan="'.(10-($i%10)).'"></td></tr>');
    

    This way, i just substracted the number from 10, which left me with the number to use with coldspan, having the row complete.

    Hope it helps some of u!!

    Thank you all

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

Sidebar

Related Questions

I'm using the mPDF library to generate PDF docs directly from HTML output. The
Good evening. I am using Yii framework and mPDF library to generate some PDF
I'm generating PDFs using mPDF library, and my header and footer vary in size
Using a populated Table Type as the source for a TSQL-Merge. I want to
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using CI for the first time and i'm smashing my head with this seemingly
Using Microsoft SQL Server 2005, is there any way to see when a table
Using RestKit 0.10.1, I have objects served similar to this json format: {objects: [
Using range() in Underscore I can make something like this: _.range(10); >> [0, 1,
I am newbie for mpdf so don't mind if you feel this question is

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.