大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺
安装
composer require tecnickcom/tcpdf
示例代码
try {
$order = requestAPI(env('A2_URL') . 'akinst/order/detail', ['user_id' => Auth::id(), 'order_number' => $request->get('p')]);
$data = Arr::get($order,'0',[]);
$data['total_amount_ch'] = convertAmountToCn(Arr::get($data,'total_amount',0));
$data['downdate'] = date('Y-m-d',time()).'星期'.mb_substr( "日一二三四五六",date("w" ,time()),1,"utf-8" );;
$view = view('tcpdf/contract', compact('data'));
$content = response($view)->getContent();
$pdf = new \TCPDF('p', 'mm', 'A4', true, 'UTF-8', false);
// set margins
$pdf->SetFont('stsongstdlight', '', 10);
$pdf->SetCreator('创作者');
$pdf->SetAuthor('作者');
$pdf->SetTitle('网络销售合同');
$pdf->SetSubject('网络销售合同');
$pdf->SetKeywords('网络销售合同');
// set default header data
$pdf->SetHeaderData('', 63, '', '头部' , array(0, 0, 0), array(0, 0, 0));
//$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setHeaderFont(Array('stsongstdlight', '', '10'));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// 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);
$pdf->SetMargins(15, 20, 15);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 0);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setPrintHeader(true);
$pdf->setPrintFooter(false);
// set some language-dependent strings (optional)
// ---------------------------------------------------------
// Add a page
$pdf->AddPage();
$html = $content;
$pdf->setPageMark();
$pdf->SetXY(15, 20);
$pdf->writeHTML($html, true, false, true, false, '');
// ---------------------------------------------------------
$tmpPath = "pdf/" . date("Ymd");
if (!Storage::disk('public')->exists($tmpPath)) {
Storage::disk('public')->makeDirectory($tmpPath);
}
$filename = date("YmdHis") . "_" . rand(0, 10000) . '.pdf';
$filepath = 'storage/' . $tmpPath . "/" . $filename;
//循环每页生成公章
for ($i = 1; $i <= $pdf->getNumPages(); $i++) {
$pdf->setPage($i);
$pdf->Image(public_path('/mallWeb/images/official.png'), 140, 220, 50, 43, '', '', '', false, 168, '', false, false, false, false, false, false);
}
$pdf->Output(public_path($filepath), 'F');
if (file_exists(public_path($filepath))) {
$retval['code'] = 0;
$retval['filename'] = url($filepath);
$retval['msg'] = '恭喜,生成合同的PDF文件成功.';
return $retval;
} else {
$retval['code'] = 1;
$retval['msg'] = '生成合同的PDF文件失败,请联系系统管理员.';
return $retval;
}
} catch (\Exception $e) {
return $e;
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/197776.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...