title: Add an External PDF file using TCPDF
body: <p>I am using <code>TCPDF</code> for generating PDF Documents. Now I Have a Scenario in which i want to add and External PDF file between my <code>TCPDF</code> Generating File. I tried it very much but i failed.</p>
  
  <p>Here is My Code</p>
  
  <pre><code>&lt;?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-&gt;SetCreator(PDF_CREATOR);
  $pdf-&gt;SetAuthor('PACRA');
  $pdf-&gt;SetTitle('Client Undertaking');
  $pdf-&gt;SetSubject('Client Undertaking');
  $pdf-&gt;SetKeywords('Client Undertaking, PDF');
  // set default header data
  $pdf-&gt;setHeaderData('','', 'CLIENT ACCEPTANCE UNDERTAKING', '', array(0,64,255), array(0,64,128));
  $pdf-&gt;setFooterData(array(0,64,0), array(0,64,128));
  // set header and footer fonts
  $pdf-&gt;setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  $pdf-&gt;setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  // set default monospaced font
  $pdf-&gt;SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  // set margins
  $pdf-&gt;SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  $pdf-&gt;SetHeaderMargin(PDF_MARGIN_HEADER);
  $pdf-&gt;SetFooterMargin(PDF_MARGIN_FOOTER);
  // set auto page breaks
  $pdf-&gt;SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  // set image scale factor
  $pdf-&gt;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-&gt;setLanguageArray($l);
  }
  // set default font subsetting mode
  $pdf-&gt;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-&gt;SetFont('dejavusans', '', 9, '', true);
  
  // Add a page
  // This method has several options, check the source code documentation for more information.
  $pdf-&gt;AddPage();
  
  // set text shadow effect
  $pdf-&gt;setTextShadow(array('enabled'=&gt;true, 'depth_w'=&gt;0.2, 'depth_h'=&gt;0.2, 'color'=&gt;array(196,196,196), 'opacity'=&gt;1, 'blend_mode'=&gt;'Normal'));
  
  //$utf8text = file_get_contents('../LICENSE.TXT', true);
  
  // Set some content to print
  $html = &lt;&lt;&lt;EOD
  
  &lt;p&gt;Clauses 11-A-(r), 12-2-(j &amp; I) &amp; Annexure F &amp; Annexure I &lt;/p&gt;
  &lt;p&gt;
  &lt;p&gt;I, in connection with the Rating of &lt;b&gt;$opTitle&lt;/b&gt;, hereby, undertake that I &lt;/p&gt;
  &lt;p&gt;I.   Or any of my Family Members do not have any Interest in it [Clause 12-2-(i)]&lt;/p&gt;
  &lt;p&gt;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) &amp; Annexure I:  3-ii-(a) &amp; (b)]&lt;/p&gt;
  &lt;p&gt;III. Am not an Associate of any director, Substantial Shareholder or senior management officer of the customers of 
  PACRA [Annexure F:  d-(i)]&lt;/p&gt;
  &lt;p&gt;IV.  Am not Substantial Shareholder of the customer being rated by PACRA [Annexure F:  d-(ii)]&lt;/p&gt;
  &lt;p&gt; V.  Am not a director of an entity being rated by PACRA [Annexure F:  d-(iii)]&lt;/p&gt;
  &lt;p&gt; 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)]&lt;p&gt;
  &lt;p&gt; 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)]&lt;/p&gt;
  &lt;p&gt;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)]&lt;/p&gt;
  &lt;p&gt;IX.  If “Yes” to any of the above statements, shall not get involved in its rating process (Annexure I: 3-ii]&lt;/p&gt;
  &lt;p&gt;X.   Shall not join any PACRA Client (including this one), within one year of relieving from PACRA [Annexure I:  3-iv] &lt;/p&gt;
  &lt;p&gt;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&lt;p&gt;
  &lt;p&gt; Capitalized terms used herein are defined in “Defined Terms” available on the website:  www.pacra.com &lt;/p&gt;
  EOD;
  
  
  
  // Print text using writeHTMLCell()
  $pdf-&gt;writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
  
  $pdf = new FPDI();
  $pdf-&gt;AddPage();
  $pdf-&gt;AddFont('courier');
  $pdf-&gt;Write(10, 'page 1 created by TCPDF');
  $pages = $pdf-&gt;setSourceFile('middle.pdf');
  for($i=0; $i&lt;$pages; $i++)
  {
       $pdf-&gt;AddPage();
       $tplIdx = $pdf-&gt;importPage($i+1);
       $pdf-&gt;useTemplate($tplIdx, 10, 10, 200);
  }
  $pdf-&gt;AddPage();
  $pdf-&gt;Write(10, 'page 2 created by TCPDF');
  
  
  
  
  $pdf-&gt;Output($fileName, 'I');
  
  //$ordernumber=1;
  
  //$pdf-&gt;Output('underTaking'.$ordernumber.'.pdf', 'F');
  
  //============================================================+
  // END OF FILE
  //============================================================+
  ?&gt;
  </code></pre>