我想從MySql資料庫匯出pdf格式的資料。我可以在mysql資料庫中做到這一點,這非常好。我試著把它自動化。我使用了FPDF庫,但資料不適合放在表格里。我搜索了一下,但無法解決這個問題。
我應該怎么做?
影像 :
我的列 :
示例內容。
我的代碼 :
<?php
require('./fpdf/fpdf.php') 。
/Database .
require_once __DIR__ . '/db_config.php'。
$connection =
mysqli_connect(DB_SERVER,DB_USER,DB_PASSWORD,DB_DATABASE)。
if(!$connection){
die("連接錯誤:" . mysqli_connect_eror())。
}
class PDF extends FPDF
{
// Page header
function Header(span class="hljs-params">)
{
$ImagePath ='image url'/span>;
//logo
$this-> Image($ImagePath,10,70,0,90) 。
$this->SetFont('Arial','B',13) 。
//向右移動。
$this->Cell(80) 。
//標題
$this-> Cell(80,10,'title', 1,0,'C')。)
//Line break
$this->Ln(20)。
}
//頁面頁腳
function Footer()
{
//定位在距底部1.5厘米處{
$this->SetY(-15)。
//Arial斜體8。
$this->SetFont('Arial','I',8) 。
//頁數
$this->Cell(0,10,'Page ' .$this-
>PageNo().'/{nb}',0,0,'C')。)
}
}
// Columns ; }
$display_heading = array('JobId'/span>=>'JobId'/span>,'ReleaseDate'=>
'ReleaseDate',
'StartingDate'=>
'StartingDate','TargetTime'=>'目標時間','作業內容'=>。
'JobContent','KindId'=>。 'KindId','JobStatus'=>'JobStatus','CustomerId''CustomerId')。)
//資料庫結果。
$result = mysqli_query($connection, "SELECT * FROM Jobs;"/span>) 或者 die("資料庫
error:". mysqli_error($connection) )。
$header = mysqli_query($connection, "SHOW columns FROM Jobs"/span>)。
//設定
$pdf = new PDF()。
//header
$pdf->AddPage()。
/foter page
$pdf-> AliasNbPages()。
$pdf->SetFont('Arial','B',8) 。
foreach($header as $heading) {
$pdf-> Cell(24,7, $display_heading[$heading['Field']],1)。)
}
foreach($result as $row) {
$pdf->Ln()。
foreach($row as $column)
$pdf->Cell(24,7,$column,1) 。
}
$pdf->輸出()。
//Connection close$connection)。
? >
uj5u.com熱心網友回復:
你可以使用GetStringWidth()來確定當前字體配置中的一個給定字串的寬度是多少毫米。在此基礎上,如果字串的寬度比你的閾值(在你的例子中是單元格寬度)寬,你可以減小字體大小或插入換行符。
$fontSize = 14;
while($pdf->GetStringWidth($text) > 80){
$pdf->setFontSize(--$fontSize) 。
}
uj5u.com熱心網友回復:
你可能想看一下 "將文本固定到單元格 "的擴展,網址是http://www.fpdf.org/en/script/script62.php。請在http://www.fpdf.org/en/script/ex62.pdf上查看生成的PDF示例,以了解它的外觀。
如果你不想這樣壓縮文本,那么類似于@stui所建議的方法可能效果最好(獲得字串寬度,并將文本分成多行)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/329852.html
標籤:
上一篇:用flask做CRUD的菜鳥錯誤
下一篇:基于編碼的JPQL多對多連接

