【问题标题】:Auto sized the cell width with text width using FPDF使用 FPDF 自动调整单元格宽度和文本宽度
【发布时间】:2017-07-04 10:36:16
【问题描述】:

我开始使用FPDF 从Mysql 导出pdf。现在我可以导出pdf了。我已经引用了this linkthis link,但我仍然无法更改单元格宽度和文本宽度。 任何人都可以提供任何建议吗?非常感谢。

<?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();
?>

【问题讨论】:

    标签: php mysql pdf fpdf


    【解决方案1】:

    你可以使用这个代码来解决这个问题......这里的概念是只有当字符串大小大于你的单元格宽度时,字体大小才会减小。

    请注意,您不能将此代码用于多行字符串。为此,您必须使用 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);
    

    使用这个链接

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

    【讨论】:

      【解决方案2】:

      检查以下答案以设置单元格宽度 Inserting an image with PHP and FPDF, failed to load big image

      根据您的问题,您可能需要将如下所示的宽度和高度传递给cell() 函数

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

      这是调整单元格的大小并将 img 加载到相同的单元格中

      【讨论】:

        猜你喜欢
        • 2015-05-04
        • 2014-10-25
        • 1970-01-01
        • 1970-01-01
        • 2014-08-28
        • 1970-01-01
        • 1970-01-01
        • 2016-01-01
        • 1970-01-01
        相关资源
        最近更新 更多