gpt4 book ai didi

php - FPDF 创建运输标签

转载 作者:行者123 更新时间:2023-11-28 23:43:09 25 4
gpt4 key购买 nike

我正在尝试使用 FPDF 创建我的一个数据库表的 pdf。基本上,我想单击一个 print 按钮并让信息自动填充到 PDF 上。我自己尝试过的失败了,我似乎无法解决这个问题。

How the printing label should look

Example of the table being used

<?php
require("fpdf/fpdf.php");

mysql_connect("localhost", "[username]","[password]") or die ("Could not connect to database");
mysql_select_db("[db_name]") or die ("Could not select database");

$query = "SELECT ID_Shipping, ID_Order, Shipping_Company FROM SeniorDB_Shipping ORDER BY `ID_Shipping` ";
$result = mysql_query($query) or die('Error, query failed');
$num_rows = mysql_num_rows($result);


class PDF extends FPDF
{
// Page header
function Header()
{
// Logo
$this->Image('minilogo.png',10,6,50);
// Arial bold 15
$this->SetFont('Arial','B',15);
// Move to the right
$this->Cell(80);
// Title
$this->Cell(55,10,'Shipping Information',1,0,'C');
// Line break
$this->Ln(20);
}
}

// Instanciation of inherited class
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);

//$pdf->Cell(40,10,'Hello World!');

while (TRUE) {

if ($row=$result[$i]) {

//positions set above
$LabelText = sprintf("%s\n%s %s\n%s, %s, %s",
$row['ID_Shipping'],
$row['ID_Order'],
$row['Shipping_Company']);


Avery5160($x,$y,&$pdf,$LabelText);

$y++; // next row
if ($y == 10 ) { // end of page wrap to next column
$x++;
$y = 0;
if ($x == 3 ) { // end of page
$x = 0;
$y = 0;
$pdf->AddPage();
}
}
$i++; //counter through result
} else {
// Error quit printing
break;
}

}
$pdf->Output();
?>

最佳答案

确保使用 $pdf->Output(); 选项,例如 $pdf->Output('I');

有关函数/类的更多信息,您可以在此处查看 http://www.tcpdf.org/doc/code/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1

关于php - FPDF 创建运输标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34030846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com