2

I am beginning to use the FPDF to export the pdf from the Mysql. Now that i can export the pdf. I have referenced this link and this link, but I still cannot change the cell width and text width. Could anyone provide any suggestions? Thank you very much.

<?php
require('mysql_table.php');

class PDF extends PDF_MySQL_Table
{
function Header()
{
//Title
$this->SetFont('Arial','',18);
$this->Cell(0,6,'Test',0,1,'C');
$this->Ln(10);
//Ensure table header is output
parent::Header();
}
}

mysql_connect('localhost','root','');
mysql_select_db('test');
$query = "SELECT * FROM test";
$result = mysql_query($query) or die(mysql_error());
$rowCount = 2;
while($row = mysql_fetch_array($result)){
$thisid = $row['ID'];
$fileName =$row['name'];
$filepath = $row['path'];
$date = $row['date'];
$rowCount++;
}
$pdf=new PDF('P','mm',array(1000,1500));
$pdf->AddPage();
$pdf->Table('select * from test');
$pdf->AddPage();
$pdf->SetFont('Arial','',14);
$pdf->Cell('','',$thisid,1);
$pdf->Cell('','',$fileName,1);
$pdf->Cell('','','','','','',false,$filepath);
$pdf->Cell('','',$date);
$pdf->Output();
?>
Community
  • 1
  • 1
user3472143
  • 79
  • 2
  • 11

2 Answers2

0

Check the below answer to set cell width Inserting an image with PHP and FPDF, failed to load big image

As per your question you may need to pass width and height like below to cell() function

$pdf->cell(1000,1000,'',$pdf->Image($image,10,10,235,$height*18/100),'PNG');

This is to resize the cell and load img into the same

Community
  • 1
  • 1
Kiran Reddy
  • 734
  • 12
  • 28
0

you can use this code to solve this problem... here the concept is only if string size greater than your cell width then font size will reduce.

Note that you can not use this code for a multi-line string. for this, you have to use MultiCell()

$table_head1=array(25,46,40,20,60);
$table_head2=array(25,20,26,20,20,16,24,40);
// some code remove from here for show actual code.
$pdf->CellFit($table_head2[7],$table_height,$item['remark'],1,0,'C',0,'',1,0);

use this link

how to auto adjust cell width in fpdf using php and mysql

pankaj
  • 1
  • 17
  • 36