更改现有PDF文件的页眉和页脚

时间:2016-09-10 11:08:16

标签: php pdf tcpdf codeigniter-3

我已将PDF上传到我的[CodeIgniter]项目中。是否可以更改该PDF的页眉和页脚并生成新的PDF文件?

以下是我的努力

 /**
    * Creates an example PDF TEST document using TCPDF
    * @package com.tecnick.tcpdf
    * @abstract TCPDF - Example: Default Header and Footer
    * @author Devendra Chauhan
    * @since 2008-03-04
    */
$filename = realpath('tcpdf_include.php');
//var_dump($filename);
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);    

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Devendra Chauhan');
$pdf->SetTitle('Invoice');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');   

// set default header data
define ('HEADER_STRING', "New Delhi");

$pdf->SetHeaderData('bluecircle.png', '20', 'Blue Circle Medi Services Pvt Ltd', HEADER_STRING, array(0,64,255), array(0,64,128));
$pdf->setFooterData(array(0,64,0), array(0,64,128)); 

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$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);  

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}   

// ---------------------------------------------------------

// set default font subsetting mode
$pdf->setFontSubsetting(true);

// set font
$pdf->SetFont('freeserif', '', 12);

// add a page
$pdf->AddPage();

// get esternal file content
$utf8text = file_get_contents('uploads/invoice.pdf', true);

// set color for text
$pdf->SetTextColor(0, 63, 127);

//Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretch=0,  $firstline=false, $firstblock=false, $maxh=0)

// write the text
//$pdf->Write(5, $utf8text, '', 0, '', false, 0, false, false, 0);
$pdf->Write(5, $utf8text);

// ---------------------------------------------------------

 //Close and output PDF document
 $pdf->Output('Report.pdf', 'I');

我在代码上方尝试但 file_get_contents 无法获取invoice.pdf文件的内容。任何人都可以提供帮助。

0 个答案:

没有答案