2017-09-14 30 views
0

TCPDF을 사용하여 PDF 문서를 생성하고 있습니다. 이제 시나리오를 작성하여 TCPDF 파일 생성 중에 외부 PDF 파일을 추가하고 싶습니다. 나는 그것을 많이 시도했지만 실패했다.TCPDF를 사용하여 외부 PDF 파일 추가

여기

<?php 

require_once('tcpdf_include.php'); 
require_once('../tcpdf.php'); 
require_once('fpdi2/src/autoload.php'); 
// 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('PACRA'); 
$pdf->SetTitle('Client Undertaking'); 
$pdf->SetSubject('Client Undertaking'); 
$pdf->SetKeywords('Client Undertaking, PDF'); 
// set default header data 
$pdf->setHeaderData('','', 'CLIENT ACCEPTANCE UNDERTAKING', '', 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 
// dejavusans is a UTF-8 Unicode font, if you only need to 
// print standard ASCII chars, you can use core fonts like 
// helvetica or times to reduce file size. 
$pdf->SetFont('dejavusans', '', 9, '', true); 

// Add a page 
// This method has several options, check the source code documentation for more information. 
$pdf->AddPage(); 

// set text shadow effect 
$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal')); 

//$utf8text = file_get_contents('../LICENSE.TXT', true); 

// Set some content to print 
$html = <<<EOD 

<p>Clauses 11-A-(r), 12-2-(j & I) & Annexure F & Annexure I </p> 
<p> 
<p>I, in connection with the Rating of <b>$opTitle</b>, hereby, undertake that I </p> 
<p>I. Or any of my Family Members do not have any Interest in it [Clause 12-2-(i)]</p> 
<p>II. Or any of my Family Members do not buy or sell, engage in any transaction or Own Securities of or of any entity related to it, other than holdings in diversified collective investment schemes [Clause 12-2-(I) & Annexure I: 3-ii-(a) & (b)]</p> 
<p>III. Am not an Associate of any director, Substantial Shareholder or senior management officer of the customers of 
PACRA [Annexure F: d-(i)]</p> 
<p>IV. Am not Substantial Shareholder of the customer being rated by PACRA [Annexure F: d-(ii)]</p> 
<p> V. Am not a director of an entity being rated by PACRA [Annexure F: d-(iii)]</p> 
<p> VI. Have not had a recent employment (within the past six (6) months) or other Significant Business or Personal Relationship with it that may cause or may be perceived as causing a Conflict of Interest [Clause 11-(A)-(r)]<p> 
<p> VII. Do not have an immediate relation (i.e., a spouse, partner, parent, child, or sibling) who currently 
works for it [Annexure I: 3-ii-(d)]</p> 
<p>VIII. Do not have any other relationship with it directly or indirectly that may cause or may be perceived as causing Conflict of Interest [Annexure I: 3-ii-(e)]</p> 
<p>IX. If “Yes” to any of the above statements, shall not get involved in its rating process (Annexure I: 3-ii]</p> 
<p>X. Shall not join any PACRA Client (including this one), within one year of relieving from PACRA [Annexure I: 3-iv] </p> 
<p>XI. At any time during the rating process, if any of the above conditions become applicable, shall immediately make Disclosure to Team Leader and withdraw from the rating assignment<p> 
<p> Capitalized terms used herein are defined in “Defined Terms” available on the website: www.pacra.com </p> 
EOD; 



// Print text using writeHTMLCell() 
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); 

$pdf = new FPDI(); 
$pdf->AddPage(); 
$pdf->AddFont('courier'); 
$pdf->Write(10, 'page 1 created by TCPDF'); 
$pages = $pdf->setSourceFile('middle.pdf'); 
for($i=0; $i<$pages; $i++) 
{ 
    $pdf->AddPage(); 
    $tplIdx = $pdf->importPage($i+1); 
    $pdf->useTemplate($tplIdx, 10, 10, 200); 
} 
$pdf->AddPage(); 
$pdf->Write(10, 'page 2 created by TCPDF'); 




$pdf->Output($fileName, 'I'); 

//$ordernumber=1; 

//$pdf->Output('underTaking'.$ordernumber.'.pdf', 'F'); 

//============================================================+ 
// END OF FILE 
//============================================================+ 
?> 

답변

0

그냥 올바른 클래스를 사용하고 $ PDF 변수를 덮어 쓰지 내 코드입니다!

<?php 

require_once('tcpdf_include.php'); 
require_once('../tcpdf.php'); 
require_once('fpdi2/src/autoload.php'); 

// create new PDF document 
$pdf = new \setasign\Fpdi\TcpdfFpdi(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 
// set document information 
$pdf->SetCreator(PDF_CREATOR); 
$pdf->SetAuthor('PACRA'); 
// 
// [...] the other code 
// 
// Print text using writeHTMLCell() 
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); 

$pdf->AddPage(); 
$pdf->AddFont('courier'); 
$pdf->Write(10, 'page 1 created by TCPDF'); 
$pages = $pdf->setSourceFile('middle.pdf'); 
for($i=0; $i<$pages; $i++) 
{ 
    $pdf->AddPage(); 
    $tplIdx = $pdf->importPage($i+1); 
    $pdf->useTemplate($tplIdx, 10, 10, 200); 
} 
$pdf->AddPage(); 
$pdf->Write(10, 'page 2 created by TCPDF'); 

$pdf->Output($fileName, 'I'); 
+0

내 사랑은 매우 모호한 오류 설명 있다는 :( – sunny

+0

... –

+0

를 작동하지 않는 그것은 보여 나 '페이지가 아닌 Working' 그때 내가 그것을 오류를 표시 식별 페이지 요소를 볼 때'자원을로드하지 못했습니다 : 서버가 500 (내부 서버 오류)의 상태로 응답했습니다. – sunny