Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用FPDF在PHP中打印PDF。_Php_Fpdf - Fatal编程技术网

如何使用FPDF在PHP中打印PDF。

如何使用FPDF在PHP中打印PDF。,php,fpdf,Php,Fpdf,我正在尝试使用FPDF库用PHP打印发票。我可以让它显示行项目,但它的格式永远不正确。我试图改变X和Y的位置,但我不能让它做我想要的。我想在左侧显示徽标和地址,在文档右侧显示发票号和订单数据 以下是我目前掌握的代码: require('includes/fpdf/fpdf.php'); //Create a new PDF file $pdf=new FPDF(); $pdf->AddPage(); //Fields Name position $Y_Fields_Name_posi

我正在尝试使用FPDF库用PHP打印发票。我可以让它显示行项目,但它的格式永远不正确。我试图改变X和Y的位置,但我不能让它做我想要的。我想在左侧显示徽标和地址,在文档右侧显示发票号和订单数据

以下是我目前掌握的代码:

require('includes/fpdf/fpdf.php');

//Create a new PDF file
$pdf=new FPDF();
$pdf->AddPage();


//Fields Name position
$Y_Fields_Name_position = 20;
//Table position, under Fields Name
$Y_Table_Position = 26;


//First create each Field Name
//Gray color filling each Field Name box
$pdf->SetFillColor(232,232,232);
//Bold Font for Field Name
$pdf->SetFont('Arial','B',12);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(5);
$pdf->Cell(25,6,'Order Date',1,0,'L',1);


$pdf->SetX(30);
$pdf->Cell(50,6,'Graphixide Order No',1,0,'L',1);


$pdf->SetX(75);
$pdf->Cell(40,6,'Artwork',1,0,'L',1);


$pdf->SetX(110);
$pdf->Cell(20,6,'PO #',1,0,'L',1);


$pdf->SetX(130);
$pdf->Cell(20,6,'Quantity',1,0,'L',1);


$pdf->SetX(150);
$pdf->Cell(25,6,'Amount',1,0,'L',1);


$pdf->SetX(175);
$pdf->Cell(25,6,'Comments',1,0,'L',1);




//Now show the 3 columns
$pdf->SetFont('Arial','',12);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(5);
$pdf->MultiCell(25,6,$column_order_date,1);


$pdf->SetY($Y_Table_Position);
$pdf->SetX(30);
$pdf->MultiCell(80,6,$column_order_no,1);


$pdf->SetY($Y_Table_Position);
$pdf->SetX(75);
$pdf->MultiCell(40,6,$column_artwork,1);




$pdf->SetY($Y_Table_Position);
$pdf->SetX(110);
$pdf->MultiCell(20,9,$column_cpo,1);


$pdf->SetY($Y_Table_Position);
$pdf->SetX(130);
$pdf->MultiCell(20,6,$column_order_quantity,1);


$pdf->SetY($Y_Table_Position);
$pdf->SetX(150);
$pdf->MultiCell(75,6,$column_order_amount,1);


$pdf->SetY($Y_Table_Position);
$pdf->SetX(175);
$pdf->MultiCell(25,10,$column_comments,1);


$pdf->SetY($Y_Table_Position);
$pdf->SetX(150);
$pdf->MultiCell(130,6,'$ '.$total,1,'R');


//Create lines (boxes) for each ROW (Product)
//If you don't use the following code, you don't create the lines separating each row
$i = 0;




while ($i < $number_of_products)
{
$pdf->SetX(45);
$pdf->MultiCell(120,6,'',1);
$i = $i +1;
}
$pdf->Output();
?>

如果混合使用单元格和多单元格,则必须预先计算每行所需的行数/高度,并在多单元格调用后手动重置X和Y位置,因为多单元格将自动将位置设置为下一行的开头


脚本中提供了一个很好的示例和一种预先计算所需行数的方法。

您能提供它输出的内容的屏幕截图吗?我没有足够的声誉来发布图像:(.我可以发布图像吗?我想您可以将图像上传到其他地方并嵌入。是的,这是链接[链接]
class PDF extends FPDF
{


function Header()
{
    // Logo
    $this->Image('images/logo.png',10,6,30);
    // Arial bold 15
    $this->SetFont('Arial','B',15);
    // Move to the right
    $this->Cell(80);
    // Title
    $this->Cell(30,10,'Title',1,0,'C');
    // Line break
    $this->Ln(20);
}


// Page footer
function Footer()
{
    // Position at 1.5 cm from bottom
    $this->SetY(-15);
    // Arial italic 8
    $this->SetFont('Arial','I',8);
    // Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}