Blogger Information
Blog 1
fans 0
comment 0
visits 381
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
thinkphp 生成pdf文件进行打印方法
老头
Original
381 people have browsed it

php学习交流找不到好的群,推荐一个 Q群:102406652

 1、首先 项目根目录运行     composer require tecnickcom/tcpdf   生成tcpdf库。   Composer中国镜像比较慢,这里推荐使用阿里云镜像   

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

老头博客网:PHP老头博客网 - PHP博客-站长和程序猿的资源库,PHP、源码、资讯、代码、教学、教程、网站开发、软件开发、APP开发。PHP老头博客网为个人站长与企业网络提供全面的站长资讯、源代码程序下载、php代码教程、操作系统安装使用、服务器技术、编程知识、优秀网站推荐、个人和企业网站运营、网页制作、软件使用技巧、网站开发、小程序开发、软件开发、互联网技术分享等。https://www.laotouw.com

2、在控制器里进行使用

<?php

namespace app\index\controller;

use think\facade\Config;
use think\Controller;
use think\Model;
use think\facade\Env;
use TCPDF;
class Question extends Controller
{
   //生成pdf文件
   public function paperWord($paper_id, $user_id, $type = 1)
   {
       $url = 'uploads/paper/' . randomFileName() . ".pdf";
       // 生成PDF
       $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
       $pdf->SetMargins(15, 15, 15);
       $pdf->SetFont('stsongstdlight', '', 12);
       $pdf->AddPage();
       $pdf->writeHTML($content, true, false, true, false, '');
       $rootPath = Env::get('root_path');
       $showType= 'F';//PDF输出的方式。I,在浏览器中打开;D,以文件形式下载;F,保存到服务器中;S,以字符串形式输出;E:以邮件的附件输出
       $filePath = $rootPath . 'public/' . $url;
       $pdf->Output($filePath, $showType);
   }
}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post