首页 > 解决方案 > 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

在此处输入图像描述

第二张图片是发票pdf 在此处输入图像描述

标签: phphtmltcpdf

解决方案


您必须使用 tcpdf 图像作为背景图像 https://tcpdf.org/examples/example_009/

并且您需要使用 tcpdf 表 https://tcpdf.org/examples/example_045/


推荐阅读