| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace app\task\controller;
- use TCPDF;
- use app\common\model\Certificate;
- class Test
- {
- public function createPdf()
- {
- // 创建新的PDF文档
- $pdf = new TCPDF();
- // 设置文档信息
- $pdf->SetCreator(PDF_CREATOR);
- $pdf->SetAuthor('Your Name');
- $pdf->SetTitle('PDF with Watermark');
- $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);
- // 设置头部和底部字体
- $pdf->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]);
- $pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]);
- // 移除默认的页脚
- $pdf->setPrintFooter(false);
- // 设置默认的单元格边距
- $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
- // 设置间距
- $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
- $pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
- // 设置图像比例因子
- $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
- // 设置默认的字体,这里设置为DejaVuSans
- // $pdf->SetFont('dejavusans', '', 14);
- // 添加页面内容
- $pdf->AddPage();
- $pdf->Write(0, "I'm a simple text to test the watermark.\n");
- // 设置水印文字
- $watermarkText = "水印水印水印水印水印";
- $pdf->SetFont('msyh', '', 50);
- // 计算斜着文字的起始坐标
- $x = $pdf->getX();
- $y = $pdf->getY();
- // 设置斜着文字的角度
- $angle = 45;
- // 使用Rotate()函数插入斜着的文字水印
- $pdf->StartTransform();
- $pdf->Rotate($angle, $x, $y);
- $pdf->SetTextColor(200, 200, 200);
- $pdf->Text($x, $y, $watermarkText);
- $pdf->StopTransform();
- // $pdf->SetTextColor(200, 200, 200);
- // $pdf->SetXY(20, 50);
- // $pdf->Write(0, 'Watermark');
- // $pdf->SetXY(100, 50);
- // $pdf->Write(0, '水印'); //中文乱码
- $pdf->Output(WEB_PATH.'temp'.'/'.'AA.pdf', 'F'); //生成PDF文件到某地
- // 输出PDF
- $pdf->Output('AA.pdf', 'I');
- }
- public function repairTask()
- {
- exit();
- $model = new Certificate();
- $list = $model->with(['file', 'category'])
- ->where('is_delete', '=', 0)->select();
- return $list->each(function ($item) {
- $item['file_type'] = $item->file['file_type'];
- $item->save();
- });
- }
- }
|