thinkphp5 tcpdf导出pdf乱码,关闭调试模式就好了
web ThinkPHP5.1 2023-02-08 709 0
关于本站

“最难不过坚持”

本人承接扒站仿站,php网站维护,病毒查杀,网站编辑,网站改版,html制作

有需要网站维护,改版,病毒查杀,网站编辑,网站备案,html制作等相关的工作可以联系我。
本人有多年相关工作经验,也可提供免费咨询,交个朋友。
有需要探讨问题的朋友,也可以加我微信,共同探讨!
微信:15011482830 QQ:408917339

6409272 2611 39
最新评论
https://jueru.net/
评 留言
:weixiao:
评 留言
:shuijiao: :weiqu: :zhenbang: :leng:
评 留言
:yiwen: :yiwen: :yiwen: :yiwen:
评 EasySass: could not generate CSS file. See Output panel for details.
这个业务逻辑多少都有点奇怪了,阅读浏览次数增值在新闻详情页的控制器方法里setInc,这怎么还写进模型事件里了。如果非要用onAfterRead也可以,把新闻文章的内容单独分出来一个news_content表,然后把它和news做关联,然后给news_content表的onAfterRead事件做增值处理,这样点进新闻页内查询到文章内容时才会触发它。
评 TP6模型事件-查询后onAfterRead不好用
文章标签更多
ThinkPHP (254)
Mysql (58)
DedeCms (33)
jQuery (67)
证件照 (1)
setInc (4)
setDec (4)
onclick (5)
打开边栏(ESC) 关闭边栏(ESC)

thinkphp5 tcpdf导出pdf乱码,如图

from clipboard

关闭tp5调试模式,就可以了

from clipboard


1.透过Composer浏览正式版TCPDF,转换到业务流程子目录运转如下表所示指示(Windows下DOS指示转换):

composer require tecnickcom/tcpdf

指示获得成功继续执行后,TCPDF会被浏览到业务流程子目录中的vendor文档夹,如图:
from clipboard

examples中有60数个众所周知实例,须要甚么机能间接看范例方可,范例相关联条目见TCPDF非官方网站:https://tcpdf.org/examples/

2.在驱动器中初始化TCPDF。

use TCPDF;

3.在方式中间接黏贴非官方实例中的标识符,获得成功运转。

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, UTF-8, false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor(Nicola Asuni); $pdf->SetTitle(TCPDF Example 001); $pdf->SetSubject(TCPDF Tutorial); $pdf->SetKeywords(TCPDF, PDF, example, test, guide); $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE. 001, PDF_HEADER_STRING, array(0,64,255), array(0,64,128)); $pdf->setFooterData(array(0,64,0), array(0,64,128)); $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, , PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, , PDF_FONT_SIZE_DATA)); $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); if (@file_exists(dirname(__FILE__)./lang/eng.php)) {     require_once(dirname(__FILE__)./lang/eng.php);     $pdf->setLanguageArray($l); } $pdf->setFontSubsetting(true); $pdf->SetFont(dejavusans, , 14, , true); $pdf->AddPage(); $pdf->setTextShadow(array(enabled=>true, depth_w=>0.2, depth_h=>0.2, color=>array(196,196,196), opacity=>1, blend_mode=>Normal)); $html = <<<EOD <h1>Welcome to <a href=”http://www.tcpdf.org” style=”text-decoration:none;background-color:#CC0000;color:black;”>&nbsp;<span style=”color:black;”>TC</span><span style=”color:white;”>PDF</span>&nbsp;</a>!</h1> <i>This is the first example of TCPDF library.</i> <p>This text is printed using the <i>writeHTMLCell()</i> method but you can also use: <i>Multicell(), writeHTML(), Write(), Cell() and Text()</i>.</p> <p>Please check the source code documentation and other examples for further information.</p> <p style=”color:#CC0000;”>TO IMPROVE AND EXPAND TCPDF I NEED YOUR SUPPORT, PLEASE <a href=”http://sourceforge.net/donate/index.php?group_id=128076″>MAKE A DONATION!</a></p> EOD; $pdf->writeHTMLCell(0, 0, , , $html, 0, 1, 0, true, , true); $pdf->Output(example_001.pdf, I);
注意事项:

1.因为TCPDF采用定界符的方式输出html等内容,因而上述标识符中的$html一直到EOD必须顶格。

2.ThinkPHP要关闭调试模式,不然输出乱码。


composer安装tcpdf后,完整使用代码

<?php
namespace app\admin\controller;

use TCPDF;
/**
 * 职员控制器
 */
class Staff extends Base
{
  /**
   * 导出pdf
   */
  function pdf() {
    $html = '<h1>pdf导出测试2222</h1>';
    
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    // 设置打印模式
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor('Nicola Asuni');
    $pdf->SetTitle('TCPDF Example 001');
    $pdf->SetSubject('TCPDF Tutorial');
    $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
    // 是否显示页眉
    $pdf->setPrintHeader(false);
    // 设置页眉显示的内容
    $pdf->SetHeaderData('logo.png', 60, 'English title', '中文标题', array(0,64,255), array(0,64,128));
    // 设置页眉字体
    $pdf->setHeaderFont(Array('dejavusans', '', '12'));
    // 页眉距离顶部的距离
    $pdf->SetHeaderMargin('5');
    // 是否显示页脚
    $pdf->setPrintFooter(true);
    // 设置页脚显示的内容
    $pdf->setFooterData(array(0,64,0), array(0,64,128));
    // 设置页脚的字体
    $pdf->setFooterFont(Array('dejavusans', '', '10'));
    // 设置页脚距离底部的距离
    $pdf->SetFooterMargin('10');
    // 设置默认等宽字体
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    // 设置行高
    $pdf->setCellHeightRatio(1);
    // 设置左、上、右的间距
    $pdf->SetMargins('10', '10', '10');
    // 设置是否自动分页  距离底部多少距离时分页
    $pdf->SetAutoPageBreak(TRUE, '15');
    // 设置图像比例因子
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
    }
    $pdf->setFontSubsetting(true);
    $pdf->AddPage();
    // 设置字体
    $pdf->SetFont('stsongstdlight', '', 14, '', true);
    $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
    $pdf->Output('example_001.pdf', 'I');
  }
}
具体可参考examples里面的案例

from clipboard

版权声明:本篇文章来源于网络。 来源链接

相关推荐
Non-static method think\Config::get() should not be called statically
ThinkPHP5.1 | 2018-12-29 10394
原来是这样use think\Config; 改成这样use think\facade\Config; 下面是官方手册的解释 配置获取 要使用Config类,首先需要在你的类文件中引入 use think\facade\Config; 或者(因为系统做了类库别名,其实就是调用think\facade\Config) u...
thinkPHP5 order多条件排序
ThinkPHP5.1 | 2017-10-24 10262
总结如下: //单一条件排序 $user = $this->where(['parentId'=>0)->field('userId,userName,userSort,isShow')->order('userSort', 'asc')->select(); //多个条件排序,可以多加一个order...
评论:0条
评论加载中...
发表评论