Thinkphp框架引用tcpdf插件,插件下载地址:待续。。。

代码编写前先引入tcpdf整个文件夹到项目目录的ThinkPHP文件夹下 如:/ThinkPHP/Library/Vendor/tcpdf

其他的不多说直接上代码

 导出考试结果明细
public function export()
{
    // 导出考试结果明细(PDF)
$id = I('id');
$detailed = D('member_test_result');
$parameter = $detailed->detailedResults($id);
$name = $parameter['member_name'];
$result = json_decode($parameter['test_result_str']);
foreach ($result as $k => $v) {
$test = M('test_cont');
$array['question_title'] = $test->where('id=' . $k)->getField('qustion_title');
//正确选项
$array['state'] = $test->where('id=' . $k)->getField('state');
//正确答案
$wheres['test_id'] = $k;
$wheres['state'] = $array['state'];
$array['stateresult'] = M('test_answer')->where($wheres)->getField('answer_name');
//选项
$array['cont'] = $v;
//选项内容
$where['test_id'] = $k;
$where['state'] = $array['cont'];
$array['result'] = M('test_answer')->where($where)->getField('answer_name');
$data[] = $array;
}
$content = '<!doctype html>';
$content .= '<html lang="en">';
$content .= '<head>';
$content .= '<meta charset="UTF-8" />';
$content .= '<title>考试结果</title>';
$content .= '</head>';
$content .= '<body>';
$content .= '<div class="content">';
$content .= '<p align="center" style="color: #0a6ebd;font-size: 24px"><b>考试结果</b></p>';
$content .= ' <div style="color:#6a6a6a;letter-spacing:4px">';
$content .= '<p><span>姓名:';
$content .= $name;
$content .= '</span>';
$content .= '<span style="color:#fff;">1231';
$content .= '</span>';
$content .= '<span style="" >考试用时:';
$content .= gmdate("i:s", $parameter['time_cost']);
$content .= '</span>';
$content .= '<span style="color:#fff;">1231';
$content .= '</span>';
$content .= '<span style="">考试分数:';
$content .= $parameter['score'];
$content .= '</span>';
$content .= '<hr/>';
foreach ($data as $k => $v) {
$content .= '<p style=font-size: 20px><b>';
$content .= $k + 1;
$content .= '、</b>';
$content .= $v['question_title'];
$content .= '</p>';
$content .= '<p style=" font-size: 14px">您的选项为:<span style="color:#0a6ebd;">';
$content .= $v['cont'];
$content .= '</span></p>';
$content .= '<p style=" font-size: 14px">您的答案为:<span style="color:#0a6ebd;">';
$content .= $v['result'];
$content .= '</span></p>';
$content .= '<p style=" font-size: 14px">正确选项为:<span style="color:red;">';
$content .= $v['state'];
$content .= '</span></p>';
$content .= '<p style=" font-size: 14px">正确答案为:<span style="color:red;">';
$content .= $v['stateresult'];
$content .= '</span></p>';
};
$content .= '</div>';
$content .= '</body>';
$content .= '</html>';
pdf($content); } pdf方法
function pdf($html){
  
vendor('Tcpdf.tcpdf');
$pdf = new \Tcpdf('P', 'mm', 'A4', true, 'UTF-8', false);
// 设置打印模式,设置文档信息
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('Examination result(考试结果)');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, PHP, example, test, guide');
// 是否显示页眉和是否显示页脚
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(true);
// 设置页眉和页脚信息内容
$pdf->SetHeaderData('logo.jpg', 40, 'Helloweba.com', '小白测试', array(0,64,255), array(0,64,128));
$pdf->setFooterData(array(0,64,0), array(0,64,128));
// 设置页眉和页脚字体
$pdf->setHeaderFont(Array('dejavusans', '', '12'));
$pdf->setFooterFont(Array('dejavusans', '', '10'));
// 设置间距
$pdf->SetHeaderMargin('5');
$pdf->SetFooterMargin('10');
// 设置左、上、右的间距
$pdf->SetMargins('10', '10', '10');
// 设置是否自动分页 距离底部多少距离时分页
$pdf->SetAutoPageBreak(TRUE, '15');
// 设置默认等宽字体
$pdf->SetDefaultMonospacedFont('courier');
// 设置行高
$pdf->setCellHeightRatio(1);
// 设置图像比例因子
$pdf->setImageScale(1.25);
//设置默认字体子集模式
$pdf->setFontSubsetting(true);
// 设置字体
$pdf->SetFont('stsongstdlight', '', 14, '', true);
$pdf->AddPage();
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
  //PDF输出 I:在浏览器中打开,D:下载,F:在服务器生成pdf ,S:只返回pdf的字符串
  $pdf->Output(rand_string('9').'.pdf', 'I');
}

thinkphp-PHP实现pdf导出功能的更多相关文章

  1. ubuntu 16.04.3配置MinDoc的PDF导出功能

    1. 安装 wkhtmltopdf,然后reboot sudo apt-get install wkhtmltopdf 2. 进入cd /usr/bin 测试一下,看目录下有没有pdf生成 wkhtm ...

  2. thinkPHP中phpexcel的导出功能

    public function wExcel() { vendor("PHPExcel.PHPExcel"); // Create new PHPExcel object $obj ...

  3. ThinkPHP 整合 PHPExcel ,数据导出功能实现,解决Invalid cell coordinate

    PHPExcel想必大家都不陌生,是用来操作Office Excel 文档的一个PHP类库,它基于微软的OpenXML标准和PHP语言.可以使用它来读取.写入不同格式的电子表格 本次只做数据导出功能的 ...

  4. asp.net导出excel-一行代码实现excel、xml、pdf、word、html、csv等7种格式文件导出功能而且美观-SNF快速开发平台

    分享: 腾讯微博  新浪微博   搜狐微博   网易微博  腾讯朋友  百度贴吧  豆瓣   QQ好友  人人网 作者:王春天  原文地址:http://www.cnblogs.com/spring_ ...

  5. React项目实现导出PDF的功能

    在做web项目中,有时候会遇到pdf导出的需求,现根据之前在公司的React项目中遇到的导出PDF需求,整理一个demo出来. 导出PDF需要用到两个依赖包:html2canvas.jspdf 1.安 ...

  6. 解决highCharts导出功能汉化问题

    本文以highCharts中文网上的例子为原型,处理解决highCharts导出功能为英文的问题. 我们使用highCharts当然希望所有提示或文本都是中文的了,但是highCharts的默认语言是 ...

  7. vue实现pdf导出,解决生成canvas模糊等问题

    最近公司项目需要,利用vue实现pdf导出,从而保存到本地打印出来,说起来好像也很容易,具体要怎么实现呢? 1 .我们要添加两个模块 第一个.将页面html转换成图片 npm install --sa ...

  8. 【HOW】如何限制Reporting Services报表导出功能中格式选项

    Reporting Services报表导出功能中缺省会提供多种导出格式选项,但很多情况下不需要全部的格式选项,因此需要对这些选项进行限制.下面我们以SQL Server 2008 R2为例来说明对这 ...

  9. Atitit.excel导出 功能解决方案 php java C#.net版总集合.doc

    Atitit.excel导出 功能解决方案 php java C#.net版总集合.docx 1.1. Excel的保存格式office2003 office2007/2010格式1 1.2. 类库选 ...

随机推荐

  1. adnroid 自定义ProgressDialog加载中

    用来记录自己所用到的知识 前两天在做项目的时候发现有时候在访问网络数据的时候由于后台要做的工作较多,给我们返回数据的时间较长,所以老大叫我加了一个加载中的logo图用来提高用户体验. 于是就在网上找了 ...

  2. 《ArcGIS Runtime SDK for Android开发笔记》

    开发笔记之基础教程 ArcGIS Runtime SDK for Android 各版本下载地址 <ArcGIS Runtime SDK for Android开发笔记>——(1).And ...

  3. 2016微软技术大会Azure相关回顾

    3 天的时间稍纵即逝,伴随着本届大会压轴大奖的揭晓,2016 年度的微软技术大会完美落幕.以“数字化转型”为主题,来自微软全球的近百位顶尖技术专家.工程师和业务负责人拔冗而至,在 130 余场的专业技 ...

  4. Winform中 DataGridView控件中的 CheckBox 的值读出来 始终 为 False ,已解决

    private void DGV_DetailsViewer_CellContentClick(object sender, DataGridViewCellEventArgs e) { )) { D ...

  5. Flask入门文件上传flask-uploads(八)

    1 视图传递多个参数 (1) 普通传参 : 关键字参数传递 return render_template('模板名称.html',arg1=val1,arg2=val2...) (2) 字典传参 : ...

  6. 【Leetcode】【Medium】Single Number II

    Given an array of integers, every element appears three times except for one. Find that single one. ...

  7. February 25 2017 Week 8 Saturday

    Energy and persistence can conquer all things. 能量和毅力可以征服一切. I have the persistence, but it seems I a ...

  8. jQuery插件编写步骤详解

    如今做web开发,jquery 几乎是必不可少的,就连vs神器在2010版本开始将Jquery 及ui 内置web项目里了.至于使用jquery好处这里就不再赘述了,用过的都知道.今天我们来讨论下jq ...

  9. 设计模式——建造者模式(BuilderPattern)

    建造者模式(Builder):将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示. UML图: Builder: package com.cnblog.clarck; /** * ...

  10. 51nod 1442 士兵的旅行

    拆点,因为只能走一步,那么u->v 后就不能到k了,这样,建图就能保证只走一步: #include <bits/stdc++.h> using namespace std; *; c ...