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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:13:15+00:00 2026-05-26T09:13:15+00:00

I am using PHP and fpdf to generate my view in pdf. My problem

  • 0

I am using PHP and fpdf to generate my view in pdf. My problem is how to limit amount of data per page?
If I have 100 rows data, the result is 10 page. So I must Limit 10 rows per page.
I have this code :

<?php

define('FPDF_FONTPATH', 'font/');
require_once("../../includes/initialize.php");

class PDF extends FPDF {

 function Header() {
     $this->Image("../icon/banner.jpg", 40, 10, 15);
 }

 function Footer() {
     $this->SetY(-15);
     $this->SetFont("Arial", "I", 10);
     $this->Cell(0, 10, "Page " . $this->PageNo() . "/{nb}", 0, 0, "C");
 } 

}
 $filter = $_GET["filter"];
 $value = $_GET["value"];
 if (!empty($_GET["filter"]) && !empty($_GET["value"])) {
 $query = "Select id_detail_ruang, id_ruang, id_barang, no_seri from detail_ruang
 where ".$filter." = '".$value."'";

} else {
 $query = "Select id_detail_ruang, id_ruang, id_barang, no_seri from detail_ruang";
}


$sql = mysql_query($query);
$data = array();
while ($row = mysql_fetch_assoc($sql)) {
 array_push($data, $row);
}

$judul = "LAPORAN KERUSAKAN";
$header = array(
 array("label" => "No. Detail Kerusakan", "length" => 25, "align" => "C"),
array("label" => "Kode Barang", "length" => 25, "align" => "C"),
array("label" => "Nama Barang", "length" => 50, "align" => "C"),
array("label" => "No Ruang", "length" => 50, "align" => "C")
);

$pdf = new PDF("L");
$pdf->AliasNbPages();
$pdf->AddPage();

$pdf->SetFont("Arial", "B", 7);
$pdf->Cell(0, 20, $judul, 0, 1, "C");
$pdf->SetFillColor(87, 190, 224);
$pdf->SetTextColor(33, 71, 84);
$pdf->SetDrawColor(255, 0, 25);
$pdf->SetAutoPageBreak(true, 30);
foreach ($header as $kolom) {
$pdf->Cell($kolom['length'], 5, $kolom['label'], 1, '0', $kolom['align'], true);
}
$pdf->Ln();

$pdf->SetFillColor(87, 190, 224);
$pdf->SetTextColor(33, 71, 84);
$pdf->SetFont('');
$fill = false;
foreach ($data as $baris) {
 $i = 0;
foreach ($baris as $cell) {
    $pdf->Cell($header[$i]['length'], 5, $cell, 1, '0', $kolom['align'], $fill);
    $i++;
}
$fill = !$fill;
$pdf->Ln();
}
$pdf->Output();
?>

I’m try using SetAutoPageBreak()
Is it Possible to do it..?
How to do it..?
Thanks

  • 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-05-26T09:13:15+00:00Added an answer on May 26, 2026 at 9:13 am

    Since you’ve already go the data in a PHP array, the simplest solution would be to use array_chunk():

    define('TABLE_SIZE', 100);
    $pages=array_chunk($data, TABLE_SIZE, true);
    
    foreach ($page as $table) {
       foreach ($table as $baris) {
          $i = 0;
          foreach ($baris as $cell) {
             $pdf->Cell($header[$i]['length'], 5, $cell, 1, '0', $kolom['align'], $fill);
             $i++;
          }
       }
       if (count($table)==TABLE_SIZE) {
          // do page break
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using PHP and FPDF to generate a PDF with a list of
I'm using fpdf library to generate some pdf files with php. At this moment
I am using php and fpdf to generate a pdf. How can I scale
I have a php file that I use to print pdf (using FPDF). In
I have a link on a page which generates a pdf. I am using
So I coded a PDF document using fpdf (PHP) However when we go to
I'm working with generating .pdf's from PHP using this library: http://www.fpdf.org/ I am currently
I am going to generate report by using FPDF . My Problem Like this
I hava a PHP script which generates a PDF file (i'm using fpdf from
I am using the FPDF library for generating PDF files by PHP. This library

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.