php - Tcpdf 使用单独的管理文件
问题描述
我正在使用 TCPDF 生成 PDF。我有两个文件。第一个文件的内容是发票内容(表格,照片等....../没有代码TCPDF)第二个文件的内容是以下代码(由我的同事编码)。
$_factorUrl = PathAllocator::getBaseUrlByPath(__FILE__)."modules/printer/views_pdf/".$billName.".php?order_id=".$orderId;
ob_start();
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
//Before Write
// set some language dependent data:
$lg = Array();
$lg['a_meta_charset'] = 'UTF-8';
$lg['a_meta_dir'] = 'rtl';
$lg['a_meta_language'] = 'fa';
$lg['w_page'] = 'page';
// set some language-dependent strings (optional)
$pdf->setLanguageArray($lg);
//After Write
$pdf->setRTL(true);
// set font
$pdf->SetFont('dejavusans', '', 12);
// add a page
$pdf->AddPage();
// Persian content
$pdf->WriteHTML(execute($_factorUrl), true, 0, true, 0);
//Close and output PDF document
//$pdf->Output("factor.pdf");
ob_end_clean();
$pdfFileName = $billName."-".$orderId.md5(rand(1,1000).microtime().UserAuth::getCustomerId().$billName.$orderId);
$_fullFilePath = $sourcePath."modules/printer/dl/".$pdfFileName.".pdf";
$pdf->Output($_fullFilePath, 'FI');
header("location: ".PathAllocator::getBaseUrlByPath(__FILE__)."modules/printer/dl/".$pdfFileName.".pdf");
现在我有输出(第二张图片),但没有应用样式,表格看起来不太好......当我将任何 tcpdf 语句添加到第一个文件时,我没有输出。例如我添加到第一个文件:
<?php
$html = '<h1>Example of HTML text flow</h1>';
?>
first image is Invoice appearance on web page
解决方案
您必须使用 tcpdf 图像作为背景图像 https://tcpdf.org/examples/example_009/
并且您需要使用 tcpdf 表 https://tcpdf.org/examples/example_045/
推荐阅读
- c# - 使用 .Net(后端)+ Angular 应用程序在 URL 中隐藏带有敏感数据的参数的正确和更简洁的方法是什么?
- javascript - Javascript图像移动
- javascript - 使用路径参数检查 NextJS 中的查询值是否为空
- xamarin - Prism Navigation - 满足特定条件时将用户导航到不同的页面
- selenium - 在 Ubuntu 上无法从 Jenkins 启动浏览器
- ios - SwiftUI TextField 重置任何点击的焦点
- java - 为什么我不能在方法中添加更多的参数
- node.js - 被model.find()查询后无法读取值
- r - 如何循环回归过滤几天
- typescript - vue.component 与组件内的导入