使用tcpdf软件 在线预览pdf文件
2013-05-06 15:46
716 查看
<?php
require_once('/var/www/html/htdocs/tcpdf/config/lang/eng.php');
//包含两个文件就加载tcpdf库
require_once('/var/www/html/htdocs/tcpdf/tcpdf.php');
require_once('/var/www/html/htdocs/database.php');
$thbgcolor ="bgcolor=\"#C9D6A6\""; //定义变量
$tdbgcolor0="bgcolor=\"#DFE3E6\"";
$tdbgcolor1="bgcolor=\"#EDF1F4\"";
$tdbgcolor2="bgcolor=\"#66CCFF\"";
$tdbgcolor3="bgcolor=\"#B0C4DE\"";
$tdbgcolor4="bgcolor=\"#FFE4C4\"";
define("MSSP_TABDEF", " border=\"1\" cellpadding=\"1\" cellspacing=\"1\"");
//定义常量
define("MSSP_TABDEF2", " border=\"1\" cellpadding=\"1\" cellspacing=\"1\" width=\"%50\"");
define("MSSP_TDWIDTH", " width=\"76\" ");
define("MSSP_TDWIDTH2", " width=\"65\" ");
define("MSSP_TDWIDTH3", " width=\"68\" ");
define("MSSP_TDWIDTH4", " width=\"76\" ");
define("MSSP_TDWIDTH5", " width=\"78\" ");
$Product_info_total = 0;
$Contract_ID = $_REQUEST['Contract_ID'];
//接收数据
$pdf_filename=$Contract_ID;
header("Content-Disposition: attachment; filename=$pdf_filename.pdf");
$sql = "select c.no Contract_No, c.Date Contract_Date, e.Name Employee_Name from tbl_contract c, tbl_employee e where c.id=65 and e.id=Employee_ID";
//从数据库查出合同为65的合同名称 合同日期和销售
display_content_pdf($Contract_ID,$msspdb,$pdf_filename);
//header("/htdocs/download/" . $pdf_filename);
function display_content_pdf($Contract_ID,$msspdb,$pdf_filename)
{
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, '30', '','*****有限公司');
//头内容 想查找常量,需到/tcpdf/config/tcpdf_config.php中查找
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
//$pdf->setLanguageArray($l);
//以上为固定的一些样式,可以改变,tcpdf_config.php文件更改常量
// ---------------------------------------------------------
// set font
$pdf->AddPage('Landscape','A4'); // 横向打印
$pdf->SetFont('stsongstdlight', '', 12);
//stsongstdlight是字体,这种字体很小,可以使用dejavusans是utf - 8的Unicode字体,如果你只需要打印标准ASCII字符,您可以使用核心字体像。helvetica或次减少文件大小。
$html = '<h2>***有限公司—用印申请单</h2>';
$pdf->writeHTML($html, true, false, true, false, '');
// writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='')
$html = display_contract_content_pdf($pdf, $Contract_ID,$msspdb);
// Dest:设置PDF输出的方式。I,默认值,在浏览器中打开;D,点击下载按钮,PDF文件会被下载下来;
// F,文件会被保存在服务器中;S,PDF会以字符串形式输出;E:PDF以邮件的附件输出。
$pdf->Output("contract_" . $pdf_filename . ".pdf","I");
}
function display_contract_content_pdf($pdf, $Contract_ID,$msspdb)
{
global $thbgcolor ;
global $tdbgcolor0;
global $tdbgcolor1;
global $tdbgcolor2;
$sql = "
select
c.no Contract_No, c.Date Contract_Date, c.Customer Contract_Customer, c.Verb_Date Contract_Verb_Date, Payment_Method,
Net_Cost,Tax_Rate,Date_Clause,Sales_Date,
Service_Cost,Capital_cost,Assessment_cost,Total_cost,Gross_Sales,Gross_Profit,Gross_margin,
Business_Date,Business_Name,Department_Date,Department_Name Department_Manager_Name,Executive_Date,Executivet_Name,
e.Name Employee_Name,
d.Name Department_Name
from tbl_contract c, tbl_employee e, tbl_department d
where
c.id=$Contract_ID
and e.id=Employee_ID
and e.Department_ID = d.ID
";
$maxrows = 10;
$result = mysql_query($sql,$msspdb) or die('fail:'.mysql_error());
while ($rs = mysql_fetch_array($result))
{
$pdf->AddPage('Landscape','A4'); // 横向打印
$pdf->SetFont('stsongstdlight', 'B', 18);
$pdf->Cell(0, 1, '****合同—用印申请单', 0, 1, 'C');
$pdf->SetFont('stsongstdlight', '', 7);
$thtml = '<br><br><br><table '.MSSP_TABDEF2 . '>';
$html = sprintf("<tr> <td %s align=\"right\">日期:</td><td>%s</td>", $tdbgcolor0, $rs['Contract_Date']);
$thtml .= $html;
$html = sprintf(" <td %s align=\"right\">合同编号:</td><td>%s</td>", $tdbgcolor0, $rs['Contract_No']
4000
);
$thtml .= $html;
$thtml .= "</tr> ";
$html = sprintf("<tr> <td %s align=\"right\">销售负责人:</td><td>%s</td>", $tdbgcolor0, $rs['Employee_Name']);
$thtml .= $html;
$html = sprintf(" <td %s align=\"right\">客户名称:</td><td>%s</td>", $tdbgcolor0, $rs['Contract_Customer']);
$thtml .= $html;
$thtml .= "</tr> ";
$html = sprintf("<tr> <td %s align=\"right\">部门:</td><td>%s</td>", $tdbgcolor0, $rs['Department_Name']);
$thtml .= $html;
$html = sprintf(" <td %s align=\"right\">合同签订日期:</td><td>%s</td>", $thbgcolor, $rs['Contract_Verb_Date']);
$thtml .= $html;
$thtml .= "</tr> ";
$thtml .= "</table>";
$thtml .= '<table '.MSSP_TABDEF . '>';
$html = sprintf("<tr> <td %s align=\"center\">合同产品信息表(销售人员填写)</td>", $tdbgcolor0);
$thtml .= $html;
$html = sprintf(" <td %s align=\"center\">考核成本信息表(产品经理填写)</td>", $tdbgcolor2);
$thtml .= $html;
$thtml .= "</tr>";
$thtml .= "<tr>";
$thtml .= '<td>';
$thtml .= display_contract_product_info_pdf($Contract_ID,$msspdb,$maxrows);
//调用方法
$thtml .= "</td> ";
$thtml .= '<td>';
$thtml .= display_contract_assessment_info_pdf($Contract_ID,$msspdb,$maxrows);//调用方法
$thtml .= "</td> ";
$thtml .= "</tr> ";
$thtml .= "<tr>";
$thtml .= '<td>';
$thtml .= display_contract_clause_info_pdf($Contract_ID,$msspdb,4,$rs['Payment_Method'],
$rs['Net_Cost'],$rs['Tax_Rate'],$rs['Date_Clause'],$rs['Employee_Name'],$rs['Sales_Date']);//调用方法
$thtml .= "</td> ";
$thtml .= '<td>';
$thtml .= display_contract_other_info_pdf($Contract_ID,$msspdb,3,$rs['Service_Cost'],$rs['Capital_cost'],
$rs['Assessment_cost'],$rs['Total_cost'],$rs['Gross_Sales'],$rs['Gross_Profit'],$rs['Gross_margin'],
$rs['Business_Date'],$rs['Business_Name'],
$rs['Department_Date'],$rs['Department_Manager_Name'],
$rs['Executive_Date'],$rs['Executivet_Name']);
//调用方法
$thtml .= "</td> ";
$thtml .= "</tr> ";
$thtml .= "</table>";
$pdf->writeHTML($thtml, true, false, true, false, '');
}
return $thtml;
}
?>
require_once('/var/www/html/htdocs/tcpdf/config/lang/eng.php');
//包含两个文件就加载tcpdf库
require_once('/var/www/html/htdocs/tcpdf/tcpdf.php');
require_once('/var/www/html/htdocs/database.php');
$thbgcolor ="bgcolor=\"#C9D6A6\""; //定义变量
$tdbgcolor0="bgcolor=\"#DFE3E6\"";
$tdbgcolor1="bgcolor=\"#EDF1F4\"";
$tdbgcolor2="bgcolor=\"#66CCFF\"";
$tdbgcolor3="bgcolor=\"#B0C4DE\"";
$tdbgcolor4="bgcolor=\"#FFE4C4\"";
define("MSSP_TABDEF", " border=\"1\" cellpadding=\"1\" cellspacing=\"1\"");
//定义常量
define("MSSP_TABDEF2", " border=\"1\" cellpadding=\"1\" cellspacing=\"1\" width=\"%50\"");
define("MSSP_TDWIDTH", " width=\"76\" ");
define("MSSP_TDWIDTH2", " width=\"65\" ");
define("MSSP_TDWIDTH3", " width=\"68\" ");
define("MSSP_TDWIDTH4", " width=\"76\" ");
define("MSSP_TDWIDTH5", " width=\"78\" ");
$Product_info_total = 0;
$Contract_ID = $_REQUEST['Contract_ID'];
//接收数据
$pdf_filename=$Contract_ID;
header("Content-Disposition: attachment; filename=$pdf_filename.pdf");
$sql = "select c.no Contract_No, c.Date Contract_Date, e.Name Employee_Name from tbl_contract c, tbl_employee e where c.id=65 and e.id=Employee_ID";
//从数据库查出合同为65的合同名称 合同日期和销售
display_content_pdf($Contract_ID,$msspdb,$pdf_filename);
//header("/htdocs/download/" . $pdf_filename);
function display_content_pdf($Contract_ID,$msspdb,$pdf_filename)
{
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, '30', '','*****有限公司');
//头内容 想查找常量,需到/tcpdf/config/tcpdf_config.php中查找
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
//$pdf->setLanguageArray($l);
//以上为固定的一些样式,可以改变,tcpdf_config.php文件更改常量
// ---------------------------------------------------------
// set font
$pdf->AddPage('Landscape','A4'); // 横向打印
$pdf->SetFont('stsongstdlight', '', 12);
//stsongstdlight是字体,这种字体很小,可以使用dejavusans是utf - 8的Unicode字体,如果你只需要打印标准ASCII字符,您可以使用核心字体像。helvetica或次减少文件大小。
$html = '<h2>***有限公司—用印申请单</h2>';
$pdf->writeHTML($html, true, false, true, false, '');
// writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='')
$html = display_contract_content_pdf($pdf, $Contract_ID,$msspdb);
// Dest:设置PDF输出的方式。I,默认值,在浏览器中打开;D,点击下载按钮,PDF文件会被下载下来;
// F,文件会被保存在服务器中;S,PDF会以字符串形式输出;E:PDF以邮件的附件输出。
$pdf->Output("contract_" . $pdf_filename . ".pdf","I");
}
function display_contract_content_pdf($pdf, $Contract_ID,$msspdb)
{
global $thbgcolor ;
global $tdbgcolor0;
global $tdbgcolor1;
global $tdbgcolor2;
$sql = "
select
c.no Contract_No, c.Date Contract_Date, c.Customer Contract_Customer, c.Verb_Date Contract_Verb_Date, Payment_Method,
Net_Cost,Tax_Rate,Date_Clause,Sales_Date,
Service_Cost,Capital_cost,Assessment_cost,Total_cost,Gross_Sales,Gross_Profit,Gross_margin,
Business_Date,Business_Name,Department_Date,Department_Name Department_Manager_Name,Executive_Date,Executivet_Name,
e.Name Employee_Name,
d.Name Department_Name
from tbl_contract c, tbl_employee e, tbl_department d
where
c.id=$Contract_ID
and e.id=Employee_ID
and e.Department_ID = d.ID
";
$maxrows = 10;
$result = mysql_query($sql,$msspdb) or die('fail:'.mysql_error());
while ($rs = mysql_fetch_array($result))
{
$pdf->AddPage('Landscape','A4'); // 横向打印
$pdf->SetFont('stsongstdlight', 'B', 18);
$pdf->Cell(0, 1, '****合同—用印申请单', 0, 1, 'C');
$pdf->SetFont('stsongstdlight', '', 7);
$thtml = '<br><br><br><table '.MSSP_TABDEF2 . '>';
$html = sprintf("<tr> <td %s align=\"right\">日期:</td><td>%s</td>", $tdbgcolor0, $rs['Contract_Date']);
$thtml .= $html;
$html = sprintf(" <td %s align=\"right\">合同编号:</td><td>%s</td>", $tdbgcolor0, $rs['Contract_No']
4000
);
$thtml .= $html;
$thtml .= "</tr> ";
$html = sprintf("<tr> <td %s align=\"right\">销售负责人:</td><td>%s</td>", $tdbgcolor0, $rs['Employee_Name']);
$thtml .= $html;
$html = sprintf(" <td %s align=\"right\">客户名称:</td><td>%s</td>", $tdbgcolor0, $rs['Contract_Customer']);
$thtml .= $html;
$thtml .= "</tr> ";
$html = sprintf("<tr> <td %s align=\"right\">部门:</td><td>%s</td>", $tdbgcolor0, $rs['Department_Name']);
$thtml .= $html;
$html = sprintf(" <td %s align=\"right\">合同签订日期:</td><td>%s</td>", $thbgcolor, $rs['Contract_Verb_Date']);
$thtml .= $html;
$thtml .= "</tr> ";
$thtml .= "</table>";
$thtml .= '<table '.MSSP_TABDEF . '>';
$html = sprintf("<tr> <td %s align=\"center\">合同产品信息表(销售人员填写)</td>", $tdbgcolor0);
$thtml .= $html;
$html = sprintf(" <td %s align=\"center\">考核成本信息表(产品经理填写)</td>", $tdbgcolor2);
$thtml .= $html;
$thtml .= "</tr>";
$thtml .= "<tr>";
$thtml .= '<td>';
$thtml .= display_contract_product_info_pdf($Contract_ID,$msspdb,$maxrows);
//调用方法
$thtml .= "</td> ";
$thtml .= '<td>';
$thtml .= display_contract_assessment_info_pdf($Contract_ID,$msspdb,$maxrows);//调用方法
$thtml .= "</td> ";
$thtml .= "</tr> ";
$thtml .= "<tr>";
$thtml .= '<td>';
$thtml .= display_contract_clause_info_pdf($Contract_ID,$msspdb,4,$rs['Payment_Method'],
$rs['Net_Cost'],$rs['Tax_Rate'],$rs['Date_Clause'],$rs['Employee_Name'],$rs['Sales_Date']);//调用方法
$thtml .= "</td> ";
$thtml .= '<td>';
$thtml .= display_contract_other_info_pdf($Contract_ID,$msspdb,3,$rs['Service_Cost'],$rs['Capital_cost'],
$rs['Assessment_cost'],$rs['Total_cost'],$rs['Gross_Sales'],$rs['Gross_Profit'],$rs['Gross_margin'],
$rs['Business_Date'],$rs['Business_Name'],
$rs['Department_Date'],$rs['Department_Manager_Name'],
$rs['Executive_Date'],$rs['Executivet_Name']);
//调用方法
$thtml .= "</td> ";
$thtml .= "</tr> ";
$thtml .= "</table>";
$pdf->writeHTML($thtml, true, false, true, false, '');
}
return $thtml;
}
?>
相关文章推荐
- 工作笔记三——使用pdf.js实现pdf文件的在线预览
- Jquery Media插件使用,解决在线预览及打开PDF文件
- 使用FlexPaper实现PDF文件在线预览
- pdf.js使用(在线预览pdf文件)
- 使用FlexPaper实现PDF文件在线预览
- 浏览器中在线预览pdf文件(不使用插件)
- 使用什么软件可以修改PDF文件中的背景颜色
- ASP.NET MVC在线预览Excel、Word、TXT、PDF文件
- Linux不用使用软件把纯文本文档转换成PDF文件的方法
- 使用指定软件在线编辑filezilla远程文件
- PDF.js在线预览pdf、图片、txt类型文件
- vue插件开发 使用pdf.js实现手机端在线预览pdf文档
- ADF12C 在线预览PDF文件 afinlineFrame
- 万万没想到,在线PDF合并比使用软件简单多了!
- JAVA用flexpaper实现在线预览PDF文件
- ASP.NET MVC在线预览Excel、Word、TXT、PDF文件
- 在线浏览pdf文件,pdfobject的简单使用
- C# web实现word 转Html、office转Html、pdf转图片 在线预览文件
- vue插件开发之使用pdf.js实现手机端在线预览pdf文档的方法
- 利用OpenOffice、flexpaper、swftools将DOC、JPG文件转PDF再转成SWF在线预览