如何在codeigniter中更改TCPDF中的标题和徽标?
问题描述:
这是标头码,在视图其生成PDF,即使我试图改变可疑代码,它仍然是产生相同的输出..如何在codeigniter中更改TCPDF中的标题和徽标?
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true,
'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Change me');
$pdf->SetTitle('Financial Report');
$pdf->SetSubject('Yearly Customer Finanacial Report');
$pdf->SetKeywords('Purchase, Sale, Order, Payment');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH,
PDF_HEADER_TITLE.' My PDF', PDF_HEADER_STRING, array(0,64,255),
array(0,64,100));
$pdf->setFooterData(array(0,64,0), array(0,64,128));
答
你必须扩展基TCPDF进入你自己的课程并重写徽标逻辑。
然后请致电new YourTcpdf()
。
require_once('tcpdf_include.php');
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
$image_file = K_PATH_IMAGES.'logo_example.jpg';
$this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
// Set font
$this->SetFont('helvetica', 'B', 20);
// Title
$this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Change me');
$pdf->SetTitle('Financial Report');
$pdf->SetSubject('Yearly Customer Finanacial Report');
$pdf->SetKeywords('Purchase, Sale, Order, Payment');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' My PDF', PDF_HEADER_STRING, array(0,64,255), array(0,64,100));
$pdf->setFooterData(array(0,64,0), array(0,64,128));
完整的例子可以在这里找到: https://tcpdf.org/examples/example_003/
但是,亲爱的怎么样?它对我来说是相当新的...... –
我在下面的帖子中已经说过了。 – Doug
好吧,让我用全新的心态来测试它......如果我达到了我想要的目标,你将获得奖励星星...... –