title: FPDF/FPDI Error: Fatal error: Class 'setasign\Fpdi\FpdfTpl' not found in
body: <p>I am attempting to watermark an existing PDF document, and this error has been tripping me up for the past two days...</p>
  
  <p>I have the FPDI library in fpdi/src/, and the fpdf library in /fpdf/</p>
  
  <p>The file throwing the error is Fpdi.php (line 27).  Here are the first 30 lines:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  /**
   * This file is part of FPDI
   *
   * @package   setasign\Fpdi
   * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
   * @license   http://opensource.org/licenses/mit-license The MIT License
   * @version   2.0.0
   */
   
  
  namespace setasign\Fpdi;
  
  use setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException;
  use setasign\Fpdi\PdfParser\Type\PdfIndirectObject;
  use setasign\Fpdi\PdfParser\Type\PdfNull;
  //use setasign\Fpdi\FpdfTpl;
  
  /**
   * Class Fpdi
   *
   * This class let you import pages of existing PDF documents into a reusable structure for FPDF.
   *
   * @package setasign\Fpdi
   */
  class Fpdi extends FpdfTpl
  {
      use FpdiTrait;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Here is my file that I am using to watermark the .pdf document on the fly:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
   $fullPathToFile = $_GET['fileToWaterMark'];
   
   require('rotation.php');
  
      require_once('fpdf/fpdf.php');
   require_once 'fpdi/src/fpdi.php';
   require_once('fpdi/src/FpdfTpl.php');
  
  
   class PDF_Rotate extends FPDI {
  
   var $angle = 0;
  
   function Rotate($angle, $x = -1, $y = -1) {
    if ($x == -1)
     $x = $this-&gt;x;
    if ($y == -1)
     $y = $this-&gt;y;
    if ($this-&gt;angle != 0)
     $this-&gt;_out('Q');
    $this-&gt;angle = $angle;
    if ($angle != 0) {
     $angle*=M_PI / 180;
     $c = cos($angle);
     $s = sin($angle);
     $cx = $x * $this-&gt;k;
     $cy = ($this-&gt;h - $y) * $this-&gt;k;
     $this-&gt;_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm', $c, $s, -$s, $c, $cx, $cy, -$cx, -$cy));
    }
   }
  
   function _endpage() {
    if ($this-&gt;angle != 0) {
     $this-&gt;angle = 0;
     $this-&gt;_out('Q');
    }
    parent::_endpage();
   }
  
   }
  
  
  
   //$fullPathToFile = "chinmay235.pdf";
  
   class PDF extends PDF_Rotate {
  
   var $_tplIdx;
  
   function Header() {
    global $fullPathToFile;
  
    //Put the watermark
    $this-&gt;Image('http://chart.googleapis.com/chart?cht=p3&amp;chd=t:60,40&amp;chs=250x100&amp;chl=Hello|World', 40, 100, 100, 0, 'PNG');
    $this-&gt;SetFont('Arial', 'B', 50);
    $this-&gt;SetTextColor(255, 192, 203);
    $this-&gt;RotatedText(20, 230, 'Raddyx Technologies Pvt. Ltd.', 45);
  
    if (is_null($this-&gt;_tplIdx)) {
  
     // THIS IS WHERE YOU GET THE NUMBER OF PAGES
     $this-&gt;numPages = $this-&gt;setSourceFile($fullPathToFile);
     $this-&gt;_tplIdx = $this-&gt;importPage(1);
    }
    $this-&gt;useTemplate($this-&gt;_tplIdx, 0, 0, 200);
  
  
   }
  
   function RotatedText($x, $y, $txt, $angle) {
    //Text rotated around its origin
    $this-&gt;Rotate($angle, $x, $y);
    $this-&gt;Text($x, $y, $txt);
    $this-&gt;Rotate(0);
   }
  
   }
  
  
   $pdf = new PDF();
   $pdf-&gt;AddPage();
   $pdf-&gt;SetFont('Arial', '', 12);
   $pdf-&gt;Output();
   ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I am fairly competent with PHP, but this error has really thrown me for a loop.  If any more information is needed, let me know and I will provide it.</p>