在 FPDF 中显示值
这是我在 php 中使用 FPDF 生成 pdf 的代码。我想在 PDF 文件中显示学期、账单月份和账单年份。我不想显示表中的值。
我想显示在页面顶部。我该怎么做?有什么建议吗?提前致谢。干杯。
<?php
session_start();
require('fpdf/fpdf.php');
//Connect to your database
$r1=$_SESSION['sem1'];
$con=mysql_connect('localhost','root','');
if(!$con)
{
die('Unable to connect'.mysql_error());
}
mysql_select_db('hostel',$con);
$result=mysql_query("SELECT r.hosteladmissionno,
r.student_name,
r.semester,
r.blockname
r.branch,
m.billmonth,m.billyear ,
(s.days_mess*perdayrate) AS mess_charges,
m.perdayrate,
s.days_mess,s.nv_tokens
FROM registration r,student_month s,messexp m
WHERE s.hosteladmissionno = r.hosteladmissionno
AND r.mess_type=m.messtype
AND m.billmonth = 'March' AND m.billyear= '2014'");
$number_of_products = mysql_numrows($result);
while($row = mysql_fetch_array($result))
{
$hostad = $row['hosteladmissionno'];
$name = $row['student_name'];
$block=$row['blockname'];
$branch=$row['branch'];
$perday=$row['perdayrate'];
$days=$row['days_mess'];
$messch= $row['mess_charges'];
$nv=$row['nv_tokens'];
$column_no = $column_no.$hostad."\n";
$column_name = $column_name.$name."\n";
$sem_details= $sem_details.$block."\n";
$comm_details= $comm_details.$branch."\n";
$course_details= $course_details.$perday."\n";
$courseyr_details= $courseyr_details.$days."\n";
$mess_details= $mess_details.$messch."\n";
$block_details= $block_details.$nv."\n";
}
mysql_close();
//Create a new PDF file
$pdf=new FPDF('P','mm','A4');
$pdf->AddPage();
//Fields Name position
$Y_Fields_Name_position = 40;
//Table position, under Fields Name
$Y_Table_Position = 46;
$pdf->Cell(15,50,'Anna University Hostels');
//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',9);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(5);
$pdf->Cell(23,6,'Admission No',1,0,'L',1);
$pdf->SetX(28);
$pdf->Cell(37,6,'Student Name',1,0,'L',1);
$pdf->SetX(65);
$pdf->Cell(18,6,'Block Name',1,0,'L',1);
$pdf->SetX(83);
$pdf->Cell(20,6,'Branch',1,0,'L',1);
$pdf->SetX(103);
$pdf->Cell(22,6,'Per Day Rate',1,0,'L',1);
$pdf->SetX(125);
$pdf->Cell(22,6,'No of Days',1,0,'L',1);
$pdf->SetX(147);
$pdf->Cell(20,6,'Mess charge',1,0,'L',1);
$pdf->SetX(167);
$pdf->Cell(18,6,'NV Token',1,0,'L',1);
$pdf->SetX(185);
$pdf->Cell(25,6,'Block Name',1,0,'L',1);
$pdf->Ln();
//Now show the 3 columns
$pdf->SetFont('Arial','',12);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(5);
$pdf->MultiCell(23,6,$column_no,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(28);
$pdf->MultiCell(37,6,$column_name,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(65);
$pdf->MultiCell(18,6,$block,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(83);
$pdf->MultiCell(20,6,$branch,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(103);
$pdf->MultiCell(22,6,$perday,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(125);
$pdf->MultiCell(22,6,$days,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(147);
$pdf->MultiCell(20,6,$messch,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(167);
$pdf->MultiCell(18,6,$nv,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(185);
$pdf->MultiCell(25,6,$block_details,1);
$i = 0;
$pdf->SetY($Y_Table_Position);
while ($i < $number_of_products)
{
$pdf->SetX(5);
$pdf->MultiCell(205,6,'',1);
$i = $i +1;
}
$pdf->Output();
?>
This is my code for generating pdf using FPDF in php. I want to display the semester, bill month and the billyear in the PDF file. I dont want to display the values in the table.
I want to display at the top of the page. How can i do this? Any suggestion? Thanks in advance. Cheers.
<?php
session_start();
require('fpdf/fpdf.php');
//Connect to your database
$r1=$_SESSION['sem1'];
$con=mysql_connect('localhost','root','');
if(!$con)
{
die('Unable to connect'.mysql_error());
}
mysql_select_db('hostel',$con);
$result=mysql_query("SELECT r.hosteladmissionno,
r.student_name,
r.semester,
r.blockname
r.branch,
m.billmonth,m.billyear ,
(s.days_mess*perdayrate) AS mess_charges,
m.perdayrate,
s.days_mess,s.nv_tokens
FROM registration r,student_month s,messexp m
WHERE s.hosteladmissionno = r.hosteladmissionno
AND r.mess_type=m.messtype
AND m.billmonth = 'March' AND m.billyear= '2014'");
$number_of_products = mysql_numrows($result);
while($row = mysql_fetch_array($result))
{
$hostad = $row['hosteladmissionno'];
$name = $row['student_name'];
$block=$row['blockname'];
$branch=$row['branch'];
$perday=$row['perdayrate'];
$days=$row['days_mess'];
$messch= $row['mess_charges'];
$nv=$row['nv_tokens'];
$column_no = $column_no.$hostad."\n";
$column_name = $column_name.$name."\n";
$sem_details= $sem_details.$block."\n";
$comm_details= $comm_details.$branch."\n";
$course_details= $course_details.$perday."\n";
$courseyr_details= $courseyr_details.$days."\n";
$mess_details= $mess_details.$messch."\n";
$block_details= $block_details.$nv."\n";
}
mysql_close();
//Create a new PDF file
$pdf=new FPDF('P','mm','A4');
$pdf->AddPage();
//Fields Name position
$Y_Fields_Name_position = 40;
//Table position, under Fields Name
$Y_Table_Position = 46;
$pdf->Cell(15,50,'Anna University Hostels');
//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',9);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(5);
$pdf->Cell(23,6,'Admission No',1,0,'L',1);
$pdf->SetX(28);
$pdf->Cell(37,6,'Student Name',1,0,'L',1);
$pdf->SetX(65);
$pdf->Cell(18,6,'Block Name',1,0,'L',1);
$pdf->SetX(83);
$pdf->Cell(20,6,'Branch',1,0,'L',1);
$pdf->SetX(103);
$pdf->Cell(22,6,'Per Day Rate',1,0,'L',1);
$pdf->SetX(125);
$pdf->Cell(22,6,'No of Days',1,0,'L',1);
$pdf->SetX(147);
$pdf->Cell(20,6,'Mess charge',1,0,'L',1);
$pdf->SetX(167);
$pdf->Cell(18,6,'NV Token',1,0,'L',1);
$pdf->SetX(185);
$pdf->Cell(25,6,'Block Name',1,0,'L',1);
$pdf->Ln();
//Now show the 3 columns
$pdf->SetFont('Arial','',12);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(5);
$pdf->MultiCell(23,6,$column_no,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(28);
$pdf->MultiCell(37,6,$column_name,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(65);
$pdf->MultiCell(18,6,$block,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(83);
$pdf->MultiCell(20,6,$branch,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(103);
$pdf->MultiCell(22,6,$perday,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(125);
$pdf->MultiCell(22,6,$days,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(147);
$pdf->MultiCell(20,6,$messch,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(167);
$pdf->MultiCell(18,6,$nv,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(185);
$pdf->MultiCell(25,6,$block_details,1);
$i = 0;
$pdf->SetY($Y_Table_Position);
while ($i < $number_of_products)
{
$pdf->SetX(5);
$pdf->MultiCell(205,6,'',1);
$i = $i +1;
}
$pdf->Output();
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不使用 FPDF 的标准“header()”扩展函数?
http://fpdf.org/en/doc/header.htm
Why dont you use the standard "header()" extend function of FPDF ?
http://fpdf.org/en/doc/header.htm
将其添加到行
$Y_Table_Position = 46
和行$pdf->Cell(15,50,'Anna University Hostels');
之间的代码中,它将显示“学期、月、年”页面右上角的灰色(将学期、月、年更改为其实际值)。如您所见,我转到 X=160,Y=0 并使用所需的文本、自定义字体和颜色创建一个新单元格,之后,我将颜色更改为黑色(因为我的默认字体颜色是白色)并转到 X =16,Y=8 所以你的“Anna University Hostels”打印在相同的位置。之后,您的表格将像以前一样被打印。
希望我理解你的问题,这就是你正在寻找的。 (如果没有留下评论:))
Add this to your code between line
$Y_Table_Position = 46
and line$pdf->Cell(15,50,'Anna University Hostels');
, It will display "Semester,Month,Year" color gray in the right top of your page (change Semester,Month,Year with their real values).As you see I go to X=160, Y=0 and create a new Cell with the desired text, custom font and color, after that, I change the color to black (beacause my default font color is white) and go to X=16,Y=8 so your "Anna University Hostels" is printed in the same position. After that you're table will be printed as before.
Hope I understad your question, and this is what you're looking for. (if not leave a comment :) )
在标题函数中设置您谈到的内容。
Set up the stuff you talked about in the header function.